-
Notifications
You must be signed in to change notification settings - Fork 362
Frequently Asked Questions
- Phan says that an internal class, constant, or function (e.g. xdebug_is_enabled, Soap, memcached, etc.) is undeclared
- Phan says that a composer dependency of my project(a class, constant, or function) is undeclared
- Phan isn't picking up my project's doc comments
- One of Phan's function or method signatures have incorrect parameter types or return types
- PHP 7.1 features such as nullable types aren't being parsed
- Phan is warning about the code using PHP 7.1/7.2 features
- A variadic function with phpdoc has unexpected types
- There are Different Issue Sets On Different Numbers of CPUs
- How to file a bug report for a crash, error, or incorrect analysis
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
.
- 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.
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)
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).
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)
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
, andCompatibleIterableTypePHP70
are emitted when thetarget_php_version
is less than '7.1'. -
CompatibleObjectTypePHP71
is emitted for theobject
typehint when thetarget_php_version
is less than 7.2.
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
.
See Different Issue Sets On Different Numbers of CPUs
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:
- Check for similar issues. If there is anything new to add, add that.
- 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.
-
Getting Started
-
Annotating Your Source Code
-
About Union Types
-
Tutorial for Analyzing a Large Sloppy Code Base
-
Incrementally Strengthening Analysis
-
Issue Types Caught by Phan
-
Phan Config Settings
-
Typing Parameters
-
How To Use Stubs
-
Speeding up Phan Analysis