phan v2.4.7 Release Notes

Release Date: 2020-01-23 // about 4 years ago
  • ๐Ÿ†• New features(CLI, Configs):

    • Add an environment variable PHAN_NO_UTF8=1 to always avoid UTF-8 in progress bars.
      ๐Ÿ”Š This may help with terminals or logs that have issues with UTF-8 output.
      Error messages will continue to include UTF-8 when part of the error.
    • ๐Ÿ‘ Allow phan --init to complete even if composer.json has no configured autoload directories,
      ๐Ÿ”ง as long as at least one directory or file was configured.
    • Add a setting error_prone_truthy_condition_detection that can be enabled to warn about error-prone truthiness/falsiness checks. New issue types:
      • PhanSuspiciousTruthyCondition (e.g. for if ($x) where $x is object|int)
      • PhanSuspiciousTruthyString (e.g. for ?string - '0' is also falsey in PHP)
    • โš™ Limit calculation of max memory usage to the running worker processes with --processes N (#3606)
    • Omit options that should almost always be on (e.g. analyze_signature_compatibility) from the output of phan --init (#3660)
    • Allow phan --init to create config file with target_php_version of '7.4' or '8.0' based on composer.json (#3671)

    ๐Ÿ†• New Features(Analysis):

    • ๐Ÿ”€ Infer that merging defined variables with possibly undefined variables is also possibly undefined. (#1942)
    • โž• Add a fallback when some types of conditional check results in a empty union type in a loop:
      If all types assigned to the variable in a loop in a function are known,
      then try applying the condition to the union of those types. (#3614)
      (This approach was chosen because it needs to run only once per function)
    • Infer that assignment operations (e.g. +=) create variables if they were undefined.
    • Properly infer that class constants that weren't literal int/float/strings have real type sets in their union types.
    • Normalize union types of generic array elements after fetching $x[$offset].
      (e.g. change bool|false|null to ?bool)
    • Normalize union types of result of ?? operator.
    • ๐Ÿ›  Fix false positives in redundant condition detection for the real types of array accesses. (#3638, #3645, #3650)
    • ๐Ÿ‘Œ Support the non-empty-string type in phpdoc comments (neither '' nor '0').
      Warn about redundant/impossible checks of non-empty-string.
    • ๐Ÿ‘Œ Support the non-zero-int type in phpdoc comments. Infer it in real types and warn about redundant checks for zero/truthiness.
    • ๐Ÿ‘Œ Support the the non-empty-mixed in phpdoc comments and in inferences.
    • ๐Ÿ›  Fix false positives possibly undefined variable warnings after conditions
      such as if (X || count($x = [])), if (X && preg_match(..., $matches)), etc.

    ๐Ÿ› Bug fixes:

    • ๐Ÿ›  Fix a crash analyzing assignment operations on $GLOBALS such as $GLOBALS['var'] += expr; (#3615)
    • ๐Ÿ›  Fix false positive Phan[Possibly]UndeclaredGlobalVariable after conditions such as assert($var instanceof MyClass when the variable was not assigned to within the file or previously analyzed files. (#3616)
    • ๐Ÿ›  Fix line number of 0 for some nodes when simplify_ast is enabled. (#3649)

    ๐Ÿ”Œ Plugins:

    • ๐Ÿ”Œ Make Phan use the real type set of the return value of the function being analyzed when plugins return a union type without a real type set.

    ๐Ÿšง Maintenance:

    • Infer that explode() is possibly the empty list when $limit is possibly negative. (#3617)
    • ๐Ÿ’… Make Phan's code follow more PSR-12 style guidelines
      (<?php on its own line, function(): T instead of function() : T, declare visibility for class constants)
    • Internal: Check if strings are non-zero length in Phan's implementation instead of checking for variable truthiness.
      ('0' is falsey)
    • ๐Ÿ‘‰ Show null as lowercase instead of uppercase (the way var_export renders it) in more places.