6.0.112026-10-15
Performance improvements:
- In the 'balanced' processfileassignment, also try splitting groups of files weighing more than half or a quarter of an even share (not only more than a whole share) and use the partition with the lowest predicted maximum load: a large class hierarchy that is under a share but placed first no longer leaves one analysis process noticeably heavier than the others (on a large codebase with --processes 4, the heaviest worker went from ~25 % above the mean to a few percent) (#5601)
- Speed up the loading of plugins' return type overrides and function call analyzers, which took ~10 s on a large codebase before the analysis processes were forked: the inherited copies of a method are found by walking the subclasses of its class instead of grouping every method of the code base by its defining method, the internal callable-parameter checks are generated once per declared method instead of once per inherited copy, and the analyzer for plugins checking callable arguments is built once per declared method (#5603)
- Add the option lazyinheritedmethods (off by default): the copies of methods that a class inherits from a parent class declared in a file excluded from analysis (e.g. a test framework) are created on their first lookup instead of when the class is hydrated. On a large codebase with many test classes this cut the wall time by 22-24 % and the peak memory of the main process by ~40 % with identical results; the verification mode PHANLAZYINHERIT_VERIFY=1 checks every lazily created copy against the copy an eager import would have made. Plugins implementing AnalyzeMethodCapability must also implement the new marker interface AnalyzeMethodSkipsInheritedCopiesCapability (their analyzeMethod() may then be called late, or not at all, for inherited copies that are never used); otherwise the option disables itself (#5605)
Bug fixes:
- Keep the type of a variable unknown when it is unknown on some branches and known on others: $x = null; if ($c) { $x = unknown(); } (or the same with try/catch, switch, a loop, ...) used to make $x exactly null because the unknown branch contributed nothing to the merged type, so PhanTypeMismatchArgument (and related issues) were reported with certainty for a value that may be anything. The merged type is now mixed (resp. T|mixed), as the ternary operator already inferred in the same situation. This also makes the issues reported by --processes N runs less dependent on which process analyzed the callee, since a callee's inferred return type is only known to the process that analyzed its file (#5602)
- Fix PhanParamTooManyInternal being reported for every call with arguments to 58 internal methods and functions that the PHP 8.2, 8.3 and 8.5 signature deltas listed with their return type only: the Random\Randomizer methods (getBytes, getInt, pickArrayKeys, shuffleArray, shuffleBytes), the unserialize methods of the date, SplFixedArray and random engine classes, Random\Engine\PcgOneseq128XslRr64::jump, the PHP 8.3 DOMNode methods contains, getRootNode, isEqualNode and replaceChildren on every DOM node class, IntlGregorianCalendar::setDate/setDateTime and curlshareinitpersistent. The deltas now have the parameters, and a signature map entry without parameters no longer replaces the parameters known from reflection (#5604)
- Fix the false positive PhanTypeExpectedObjectOrClassName for new $x() when $x has the type object without a known class, e.g. a mixed value narrowed by method_exists($x, 'run') to class-string|object: new $obj() creates an instance of the class of $obj, whatever that class is. The expression now has the type object (#5606)
6.0.102026-10-12
本次修复集中在这几处类型推断:
/ @var int / public mixed $value;这类写法此前在6.0.8被误判为?int,导致传入int参数时报PhanTypeMismatchArgumentNullable。现在mixed不再保留可空性,@var的类型直接生效,与无原生类型属性的处理一致;只有?Box这样的显式可空类型才保留null。
try块中以throw结束的分支里赋值的变量,在catch中不再被误报为PhanUndeclaredVariable或恒为null——现在每个throw语句处的变量状态都会纳入catch的分析。
另外修了两类误报:$x已知为null时,$x?->method()和$x?->prop因空安全运算符短路,不会再触发PhanNonClassMethodCall;数组形状与mixed联合类型上的下标读取(如$g[$k]['tax'])不再凭空带上null,赋值类型已知时结果为int,未知则为unknown,不会再误报可空参数的类型不匹配。
6.0.92026-10-12
6.0.8的若干回归问题已在本版修复:
针对接口I的class-string<I>误报已解决——接口未声明的静态方法、静态属性和类常量(如枚举的cases())不再被当作未定义;new $class()的实参也只在目标类声明了构造函数或是final类时才做校验。
Reflection相关三处参数校验恢复正常:ReflectionProperty::setValue(null, $value)、ReflectionProperty::getValue(null)和ReflectionMethod::getClosure(null)的首个参数本就接受?object,与PHP一致,不再抛出PhanTypeMismatchArgumentInternalProbablyReal。
另修掉一处全局作用域下的误报:当三元表达式作为调用实参或出现在return中、其条件对变量做了收窄时,条件访问器不再改动共享的全局作用域,从而避免对?''|?'0'|?0|?0.0|?array{}|?false这类假值类型误报PhanTypeMismatchArgumentNullable。
6.0.82026-10-11
Phan本版在类型推断上更进一步:@return、@psalm-return、@phan-return支持PHPStan/Psalm风格的条件返回类型@return ($x is null ? A : B),并配套新增PhanCommentReturnConditionalWithoutRealParam告警;算术结果在符号可判定时会推断为positive-int、non-zero-int等类型。另新增--dump-phase-timings与--phase-timings-json <path>统计各阶段耗时与内存,配置项processfileassignment可让文件在--processes N多进程间分配更均衡。
性能方面,大项目解析阶段提速约12%,FQSEN与Type、UnionType的开销降低,继承方法的声明分析改为复用而非重跑;工作进程退出时跳过PHP关闭流程,避免复制共享页(PHANDISABLEFAST_EXIT=1可恢复旧行为)。
修复上,多进程输出按worker顺序合并,结果不再随调度变化;条件中$x?->method()这类空安全访问会被收窄为非空;define()声明的常量保留真实类型并支持constant('NAME')推断。此外解决了is_callable()在交集类型上的崩溃、class-string<Foo>静态调用无法解析、@var Foo<T>丢失模板参数,以及PhanImpossibleConditionInGlobalScope、PhanTypeMismatchPropertyDefault等多处误报。
6.0.72026-06-23
本版为两处修复:Redis::setnx()与RedisCluster::setoption()的stub参数定义此前有误,现已更正;StringFunctionPlugin在被检查函数使用命名参数跳过位置参数时,会因Undefined array key 1崩溃,该问题也已解决,相关调用不会再导致分析中断。
6.0.62026-06-23
New features:
- Add non-falsy-string type (excludes both '' and '0'); align non-empty-string with PHPStan/Psalm semantics to only exclude '' — !== '' now narrows to non-empty-string while if ($x) narrows to non-falsy-string (#5514, #5517)
Bug fixes:
- Fix PhanUndeclaredVariable false positive for the implicit $value parameter in property set hooks that have no explicit parameter node (#5512, #5513)
- Fix PhanImpossibleTypeComparison false positive when comparing a string to '0' after narrowing out '' (#5514, #5517)
- Fix class_exists() check losing the <T> generic parameter from class-string<T> variables inside the if-branch (#5515, #5518)
- Fix PhanInvalidConstantExpression false positive for closures and arrow functions in constant expressions on PHP 8.5 (#5516, #5519)
- Fix false positive PhanPossiblyUndeclaredVariable for variables assigned in a try block when there is no catch (#4419, #5520)
- Fix parsing failure for union types with spaces around | or & inside array shape (array{...}) and generic (array<...>) annotation syntax (#5521, #5524)
- Fix false positive PhanTypeMismatchArgument when a @template T of A|B parameter is passed to a function expecting A|B (#5522, #5525)
- Fix PhanConstantTypeMismatchInheritance false positive for covariant class constant overrides where the child's type is a proper subtype of the parent's (#5528, #5530)
- Fix false positive PhanAccessReadOnlyProperty when using ??= as a lazy-initialization pattern on non-nullable native readonly properties (#5531, #5532)
- Fix self keyword being incorrectly rejected inside arguments of attributes applied to classes (#5536, #5537)
- Fix false positive PhanIncompatibleRealPropertyType when a child class redeclares a property with the same intersection type as the parent — intersection types are now interned so identity comparisons work correctly (#5534, #5539)
- Fix PhanReadOnlyPrivateProperty false positive when using compound assignment operators (??=, +=, etc.) on array keys of a private property (#5538, #5540)
- Fix false positive PhanTypeMissingReturnReal for : never-declared functions whose last statement calls another never-returning userland function — was intermittent due to AST node flag caching (#5535, #5541)
- Fix child class properties that redeclare a parent property (e.g. to widen visibility or via @inheritDoc) without their own type annotation being assigned an empty union type instead of inheriting the parent's type (#5544, #5545)
Miscellaneous:
- Fix Redis::mget() and Redis::mset() stub signatures (#5529)
- Fix Redis::setnx() and RedisCluster::setoption() stub parameter definitions (#5546)
- Fix StringFunctionPlugin crash with Undefined array key 1 when checked functions are called with named arguments that skip positional parameters (#5547, #5548)
- Update Composer to 2.9.8 in Docker test environment (#5533)
6.0.52026-03-27
Phan本次更新聚焦于类型推断的准确性。配置项overridereturntypes正式废弃,由trackallinferred_types接替:新选项完全涵盖旧项的行为,还会在接口类型属性上持续累积具体类型,值得尽快迁移。
修复方面,json_decode()在多种flag组合下的返回值类型误报已消除,@inheritDoc相关的误报也一并处理。另外为ArrayShapeType::withStaticResolvedInContext加上了递归深度限制,自引用的数组形状不会再把分析拖入无限递归。
6.0.42026-03-24
修复了DependentReturnTypeOverridePlugin插件的崩溃问题:以命名参数调用函数并跳过前面的位置参数时(例如jsondecode($data, flags: JSONOBJECTASARRAY)),之前会直接崩溃,现在能正常处理返回类型推断。
6.0.32026-03-24
新增:AnalyzeCallableArgumentCapability插件接口会自动捕获全代码库中的可调用类型参数,省去样板代码;CaseMismatchPlugin用于查出类、函数、方法与命名空间引用的大小写不一致。新增--analyze-until-convergence标志,--analyze-twice改为只重析推断类型有变的文件,多轮分析更省时;trackallinferredtypes配置可跨赋值累计接口类型属性上的具体类型。addsuppressions.php新增--from-checkstyle,可直接读取Phan的checkstyle XML输出;@inheritDoc没有可继承内容时给出警告
Phan 6.0.22026-03-05
New features:
- Add class, interface, and trait hierarchy tables to PhoundPlugin's SQLite database (#5443, #5460)
- Add function/method signatures and parameter tables to PhoundPlugin's SQLite database (#5458)
- Improve type narrowing for comparisons with 0 and '' — infer positive-int/negative-int for ordering comparisons, and non-zero-int/non-empty-string
for inequality comparisons (#5452)
- Add Phan-Agents.md guidance document for coding agents (#5461)
Bug fixes:
- Fixed false PhanRedundantValueComparison when real type resolution returns no types (#5422)
- Fixed false PhanPossiblyUndeclaredMethod/PhanPossiblyNonClassMethodCall from wider union type assignments to typed properties (#5440)
- Fixed false PhanRedundantCondition/PhanCoalescingNeverNull for isset() and ?? on ArrayAccess objects (#5441)
- Fixed InvalidFQSENException crash on method calls on non-empty-mixed typed variables (#5442)
- Fixed false PhanTypePossiblyInvalidDimOffset warnings when accessing keys on mixed-typed variables with inferred array shapes (#5444)
- Fixed false PhanTypePossiblyInvalidDimOffset when array<string,mixed> or array<int,mixed> is in the union type (#5455)
- Fixed get_class() return type to erase template parameters from class-string<> (#5454)
- Fixed false PhanUnreferencedUseNormal when class references (A::class, A::CONST) appear in large arrays subject to literal array summarization (#5462)
- Fixed nullsafe method call type inference losing nullability when it comes from PHPDoc annotations (#5463)
- Fixed Xdebug restart handler for PHP 8.4+ where proc_open no longer passes file descriptors (#5464)
Miscellaneous:
- Replace felixfbecker/advanced-json-rpc with danog/advanced-json-rpc, allow sabre/event 6.0 (#5450)