[go: nahoru, domu]

Skip to content

Frequently Asked Questions

Tyson Andre edited this page Aug 23, 2018 · 35 revisions

Table of Contents

Common Questions

Phan says that an internal class, constant, or function (e.g. xdebug_is_enabled, Soap, Memcached, etc.) is undeclared

For the best results, run Phan with the same extensions (and same extension versions) installed and enabled as you would in the project being enabled.

Phan supports internal stubs. Regular stubs are another option for older Phan releases.

Phan automatically disables xdebug for performance reasons. If your project uses xdebug, enable the corresponding internal stubs in your project's .phan/config.php.

Phan says that a composer dependency of my project(a class, constant, or function) is undeclared

  • You must add the directory (or file) of that dependency to 'directory_list' or 'file_list' in .phan/config.php. Usually, you will want to add 'vendor' to 'exclude_analysis_directory_list' as well. See https://github.com/phan/phan/wiki/Getting-Started#creating-a-config-file
  • Make sure that the file exists in vendor/ (e.g. make sure that composer.phar install was executed if this is running in CI)
  • Make sure that there are no typos in the variable name, that the namespace of the class is correct, and that the file containing the class/constant/function exists.

This is a common cause of PhanUndeclaredClassMethod, PhanUndeclaredClass, PhanUndeclaredFunction, etc.

Phan isn't picking up my project's doc comments

See https://github.com/phan/phan/wiki/Annotating-Your-Source-Code#doc-blocks (Common issues: Phan does not support inline doc comments, doc comments must begin with /**, etc)

One of Phan's function or method signatures have incorrect parameter types or return types

Double check the documentation and examples provided on php.net (or for the latest stable version of that extension).

If Phan is inconsistent with the documentation, create a PR modifying the related functions/methods in https://github.com/phan/phan/blob/master/src/Phan/Language/Internal/FunctionSignatureMap.php (or file an issue).

PHP 7.1 features such as nullable types aren't being parsed

Make sure that Phan is being invoked with php 7.1 (or newer). For best results, the PHP version should be close to the version of the project being analyzed.

The PHP version used to invoke Phan must be 7.1 or newer to parse php 7.1 code with php-ast (As well as for getting the real function and method signatures, etc.). php-ast uses the current PHP version's internal parse tree.

The CLI options --force-polyfill-parser and/or --use-fallback-parser may also be used, but the pure PHP parser implementation has bugs in a few edge cases. (and they're slower)

Phan is warning about the codebase using syntax that is incompatible with php 7.0/7.1/7.2

This can be solved by setting the target_php_version in your .phan/config.php to '7.1'/'7.2' (if that is the oldest php version your project supports), or by changing the code to stop using newer syntax. You may also suppress that issue in .phan/config.php, and various other ways.

  • CompatibleNullableTypePHP70, CompatibleShortArrayAssignPHP70, CompatibleKeyedArrayAssignPHP70, CompatibleKeyedArrayAssignPHP70, and CompatibleIterableTypePHP70 are emitted when the target_php_version is less than '7.1'.
  • CompatibleObjectTypePHP71 is emitted for the object typehint when the target_php_version is less than 7.2.

A variadic function with phpdoc has unexpected types

The union type Phan reads for @param before ... is the union type of individual elements that are passed by the caller, not the type within the function body. The below is an example of how a function should be documented.

/** @param string ...$args (should be string, not string[] or array, and include "..." before the parameter name) */
function my_function(string ...$args) {}
my_function('arg1', 'other_arg');

See the phpdocumentor2 implementation It parses the individual element types as string from @param string ...$varName. This detail of phpDocumentor2 is also documented in the phpDocumentor/fig-standards repo.

@phan-param can be used if you must use a different standard for documenting variadic $args with @param.

There are Different Issue Sets On Different Numbers of CPUs

See Different Issue Sets On Different Numbers of CPUs

How to file a bug report for a crash, error, or incorrect analysis

Install dev-master of Phan (e.g. from composer) and see if the issue still occurs. It may have been fixed recently.

If the issue continues to happen on dev-master, then:

  1. Check for similar issues. If there is anything new to add, add that.
  2. If there are no similar issues, then file an new issue with any of the relevant information:
    • stack trace for a crash
    • Code snippets (or a link to an affected project, if possible) and config settings (if any) needed to reproduce the issue.
    • Phan version used.
    • Observed behavior and expected behavior.