Repository navigation
Commit 8a25d14
Compare constant scalars refined by accessory types against other union members in
- `TypeCombinator::union()` buckets every type whose `isConstantScalarValue()` is yes into
per-class scalar groups that are never compared with each other. An intersection such as
`'Foo'&hasMethod(m1)` (produced by `method_exists()` / `property_exists()` on a constant
class-string) landed in the `IntersectionType` bucket, so `'Foo'|('Foo'&hasMethod(m1))`
was never collapsed to `'Foo'`.
- After N `method_exists($class, $method)` checks (e.g. a foreach over a constant array
being unrolled) the type of `$class` grew to 2^N union members, making analysis time
exponential.
- Such intersections now stay with the regular types, where `compareTypesInUnion()`
absorbs them into the plain constant scalar or into a less refined intersection.
- Ported the same change to the native mirror in `turbo-ext/src/TypeCombinator.cpp`.
- Probed analogous constructs: `property_exists()` on a constant class-string had the same
problem and is fixed by the same change (covered by the test); enum cases, objects and
integers passed to `method_exists()`/`property_exists()` already collapsed correctly.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>TypeCombinator::union()
1 parent 4ef9ab7 commit 8a25d14
5 files changed
Lines changed: 64 additions & 3 deletions
File tree
- src/Type
- tests
- PHPStan/Analyser/nsrt
- bench/data
- turbo-ext/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1678 | 1678 | | |
1679 | 1679 | | |
1680 | 1680 | | |
1681 | | - | |
| 1681 | + | |
1682 | 1682 | | |
1683 | 1683 | | |
1684 | 1684 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
420 | 420 | | |
421 | 421 | | |
422 | 422 | | |
423 | | - | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
424 | 427 | | |
425 | 428 | | |
426 | 429 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1040 | 1040 | | |
1041 | 1041 | | |
1042 | 1042 | | |
1043 | | - | |
| 1043 | + | |
1044 | 1044 | | |
1045 | 1045 | | |
1046 | 1046 | | |
| |||
0 commit comments