packagist phan/phan 2.7.2
Release 2.7.2 supporting PHP 7.0-7.4 syntax

latest releases: v5.x-dev, dev-fix-4782, dev-MapReal-php81-82...
3 years ago

New features(CLI, Config):

  • Add a --native-syntax-check=/path/to/php option to enable InvokePHPNativeSyntaxCheckPlugin
    and add that php binary to the php_native_syntax_check_binaries array of plugin_config
    (treated here as initially being the empty array if not configured).

    This CLI flag can be repeated to run PHP's native syntax checks with multiple php binaries.

New features(Analysis):

  • Emit PhanTypeInvalidThrowStatementNonThrowable when throwing expressions that can't cast to \Throwable. (#3853)

  • Include the relevant expression in more issue messages for type errors. (#3844)

  • Emit PhanNoopSwitchCases when a switch statement contains only the default case.

  • Warn about unreferenced private methods of the same name as methods in ancestor classes, in dead code detection.

  • Warn about useless loops. Phan considers loops useless when the following conditions hold:

    1. Variables defined within the loop aren't used outside of the loop
      (requires unused_variable_detection to be enabled whether or not there are actually variables)

    2. It's likely that the statements within the loop have no side effects
      (this is only inferred for a subset of expressions in code)

      (Enabling the plugin UseReturnValuePlugin (and optionally 'plugin_config' => ['infer_pure_methods' = true]) helps detect if function calls are useless)

    3. The code is in a functionlike scope.

    New issue types: PhanSideEffectFreeForeachBody, PhanSideEffectFreeForBody, PhanSideEffectFreeWhileBody, PhanSideEffectFreeDoWhileBody

  • Infer that previous conditions are negated when analyzing the cases of a switch statement (#3866)

  • Support using throw as an expression, for PHP 8.0 (#3849)
    (e.g. is_string($arg) || throw new InvalidArgumentException())
    Emit PhanCompatibleThrowException when throw is used as an expression instead of a statement.

Plugins

  • Emit PhanPluginDuplicateCatchStatementBody in DuplicateExpressionPlugin when a catch statement has the same body and variable name as an adjacent catch statement.
    (This should be suppressed in projects that support php 7.0 or older)
  • Add PHP53CompatibilityPlugin as a demo plugin to catch common incompatibilities with PHP 5.3. (#915)
    New issue types: PhanPluginCompatibilityArgumentUnpacking, PhanPluginCompatibilityArgumentUnpacking, PhanPluginCompatibilityArgumentUnpacking
  • Add DuplicateConstantPlugin to warn about duplicate constant names (define('X', value) or const X = value) in the same statement list.
    This is only recommended in projects with files with too many global constants to track manually.

Bug Fixes:

  • Fix a bug causing FQSEN names or namespaces to be converted to lowercase even if they were never lowercase in the codebase being analyzed (#3583)

Miscellaneous:

  • Replace PhanTypeInvalidPropertyDefaultReal with TypeMismatchPropertyDefault (emitted instead of TypeMismatchProperty)
    and TypeMismatchPropertyDefaultReal (#3068)
  • Speed up ASTHasher for floats and integers (affects code such as DuplicateExpressionPlugin)
  • Call uopz_allow_exit(true) if uopz is enabled when initializing Phan. (#3880)
    Running Phan with uopz is recommended against (unless debugging Phan itself), because uopz causes unpredictable behavior.
    Use stubs or internal stubs instead.

Don't miss a new phan release

NewReleases is sending notifications on new releases.