[php-src] PR #24107: Fix type inference of compound assignment to typed properties
| From: | ndossche | Date: | Sat, 03 Oct 2026 21:44:10 +0000 |
| Subject: | [php-src] PR #24107: Fix type inference of compound assignment to typed properties | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-39121@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/24107
Author: ndossche
The result of ASSIGN_OBJ_OP and ASSIGN_STATIC_PROP_OP is coerced to the property type, but only
DOUBLE->LONG and LONG/DOUBLE->STRING coercions were modelled. Other coercions resulted in an
empty or too narrow type. When the property is unknown, BOOL and DOUBLE were also missing.
Inferred result type of
$o->p OP= $v in weak mode:
| Property | Value | Old | New | Runtime |
|---|---|---|---|---|
| int | float | long | long | int |
| ?int | float | long | long | int |
| int\|float | float | double | double | float |
| int\|false | float | long | long | int |
| string | int | string | string | string |
| string\|bool | int | string | string | string |
| bool | int | (empty) | bool | bool |
| float | int | (empty) | double | float |
| float\|bool | string | (empty) | double\|bool | float, bool if
non-numeric |
| int\|string | float | long | long\|string | int, string for
INF/NAN |
| int\|bool | float | long | long\|bool | int, bool for
INF/NAN |
| (unknown) | any | +long\|string | +scalar | any scalar |
In strict mode, only int -> float coercion remains, e.g. a float property with an int value
infers double, and an unknown property only adds double to the value type.