Commit e76d963
Track static-ness of closures in ClosureType to exclude null from bindTo()/bind() return type
Add an optional `?TrinaryLogic $isStatic` parameter to ClosureType's
constructor to track whether a closure was declared with the `static`
keyword. ClosureTypeResolver now passes this from the AST node.
The bind extensions use this to exclude null from the return type when
the closure is known to be non-static (binding always succeeds for
non-static closures regardless of $newThis). For static or
possibly-static closures with non-null $newThis, the return type
remains BenevolentUnionType(Closure|null) since PHP returns null when
binding an object to a static closure.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>1 parent 6f41577 commit e76d963
3 files changed
Lines changed: 21 additions & 4 deletions
File tree
- src/Type/Php
- tests/PHPStan/Analyser/nsrt
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
38 | 42 | | |
39 | 43 | | |
40 | 44 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
37 | 41 | | |
38 | 42 | | |
39 | 43 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
| 25 | + | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
34 | 40 | | |
35 | 41 | | |
36 | 42 | | |
37 | | - | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
0 commit comments