Repository navigation
Keep the PHP 8 throw types of built-in functions in a version range below PHP 8 - #7100
SanderMuller wants to merge 1 commit into
Conversation
…elow PHP 8 With a PHP version range such as 7.4 to 8.5, the stubs of the minimum version do not have the @throws tags that PHP 8 added, so getThrowType() returns null. The throw type extensions of array_chunk(), str_split(), min(), max(), the printf() family, version_compare(), array_combine() and round() returned that null, and a catch of ValueError around these calls was reported as dead. These extensions now fall back to ValueError (and ArgumentCountError for the printf() family) when the range only maybe includes PHP 8, like the range() extension does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
I am not sure about this one. is this something which really needs custom handling in every |
|
Partly, yes. BetterReflection removes the The other 4 still need an extension change:
The core part needs a change in ondrejmirtes/better-reflection, for example a maximum version for the stubber. It also changes the throw type of the other functions and methods in its PHP 8 list. Do you prefer that, with only the 4 extension changes left here? |
With a PHP version range such as
phpVersion: {min: 70400, max: 80500}, a catch ofValueErroraround these calls is reported as dead:PHP 8 throws
ValueErrorhere when$lengthis below 1. The same happens forstr_split(),min(),max(), theprintf()family,version_compare(),array_combine()andround().PHPStan reads the stubs for the minimum version of the range. Below PHP 8, BetterReflection removes the
@throwstags that PHP 8 added, or it picks a PHP 7 stub without them. SogetThrowType()returns null. The throw type extensions of these functions returned that null, andFuncCallHandlerthen adds no throw point. Functions without an extension are not affected, because with the defaultimplicitThrowsa null throw type gives an implicit throw point.The fix follows #6539, which added the same fallback to the
range()extension:ValueErrorwhengetThrowType()is null.min()andmax()returnedVoidTypewhen the range did not certainly include PHP 8. They now do that only when it certainly does not.array_combine()had no version check. It now returns null when the PHP version is below 8. This keeps the old result for a PHP 7 version.printf()family addsValueError, andArgumentCountErrorfor the functions that take the values as arguments. A null check is not enough there, because the stubs keepArgumentCountErrorforvprintf()andvfprintf().I left out
unserialize(), because #6624 changes the same extension.The new cases in
unthrown-exception-php-version-range.phpfail without the change insrc. With a probe file, the errors do not change for a fixed PHP 7.4, 8.0 or 8.5 version, or for an 8.0 to 8.5 range.🤖 Generated with Claude Code