Commit c229525
Fix divergences between the native extension and the PHP implementations
Found by a line-by-line review of every shadowed pair against its PHP twin:
- The parser dropped T_BAD_CHARACTER only below the grammar's symbol-map size,
but its id (411 on PHP 8.5) sits exactly at that bound — a stray control
byte threw RangeException instead of parsing with a collected error. The
drop-token table has its own size; bound both checks by it.
- String_::parseEscapeSequences() throwing (oversized \u{...} codepoints in
interpolated strings and backticks) left a raw pending PhpParser\Error where
doParse()'s catch block hands it to the error handler. The translation
createNode already did is extracted into abortForPendingException() and the
escape-sequence helper routes through it.
- The node-class registry latched the first caller's useCtor flag, so
isInstanceOf('Node\Arg') — reached by parsing exit(...)/die(...) — poisoned
Node\Arg into the constructor path, whose attributes-last convention Arg's
signature breaks: every later file with call arguments failed with a
TypeError. The property-write plan is now derived lazily and the path chosen
per call.
- TrinaryLogic::lazyMaxMin([]) threw ShouldNotHappenException; the PHP twin
returns Yes ( starts at YES). The class is @api, so third parties can
hit the empty case.
- ScopeOps::finishMerge()'s array_merge() renumbered integer-coerced
expression keys (an expression printing as '5' is stored under int key 5),
corrupting them — the native side preserves keys. The PHP twin now uses +
(the key sets are disjoint by construction).
- CombinationsHelper's eagerly materialized product could overflow zend_ulong
and silently truncate; it now fails loudly at PRODUCT_LIMIT. Inner elements
are dereferenced like the twin's by-value foreach.
- NodeTraverser owns references to the current subnode across visitor hooks
and to the visitors in its plan — userland writes to the parent property or
the visitor list mid-traversal could otherwise free objects still in use.
- ScopeOps::getTypeFromCache() writes the by-ref $key on hit and miss (the
twin assigns it unconditionally), and treats a stored null as a miss exactly
like the twin's ?? null.
- The array_map-args suffix of an expression key appended full node keys
(re-appending /*pos:...*/ and /*keepVoid*/ suffixes of the arguments) where
the twin appends plain printExpr() output.
- Pass 2 of matchConditionalExpressions() validates holder types like Pass 1
instead of reading property slots type-confused.
- zv.h's Ref::assign()/ObjRef::propAtWrite() install the new value before
destroying the old one (the engine's assignment idiom), so a __destruct
re-reading the slot cannot observe a freed zval.
Corpus fixtures cover the three parser bugs (malformed input and the
first-class-callable exit ordering); smoke covers lazyMaxMin([]).
Interleaved re-benchmark after the fixes: user CPU and Used memory unchanged
(-17% vs PHPSTAN_TURBO=0, +5-6% memory), analysis output byte-identical.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LVQhbBxDjDVAVeJVvLpWYE1 parent 0e60a94 commit c229525
16 files changed
Lines changed: 254 additions & 105 deletions
File tree
- src/Analyser
- turbo-ext
- src
- parser
- tests
- parser-fixtures
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
29 | 28 | | |
30 | 29 | | |
31 | 30 | | |
| |||
307 | 306 | | |
308 | 307 | | |
309 | 308 | | |
310 | | - | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
311 | 314 | | |
312 | 315 | | |
313 | 316 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
22 | 26 | | |
23 | 27 | | |
24 | 28 | | |
| |||
57 | 61 | | |
58 | 62 | | |
59 | 63 | | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
60 | 80 | | |
61 | 81 | | |
62 | 82 | | |
63 | 83 | | |
64 | | - | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
65 | 87 | | |
66 | 88 | | |
67 | 89 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
203 | 203 | | |
204 | 204 | | |
205 | 205 | | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
206 | 212 | | |
207 | 213 | | |
208 | 214 | | |
| |||
370 | 376 | | |
371 | 377 | | |
372 | 378 | | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
373 | 384 | | |
374 | 385 | | |
375 | 386 | | |
| |||
401 | 412 | | |
402 | 413 | | |
403 | 414 | | |
| 415 | + | |
404 | 416 | | |
405 | 417 | | |
406 | 418 | | |
| |||
465 | 477 | | |
466 | 478 | | |
467 | 479 | | |
| 480 | + | |
468 | 481 | | |
469 | 482 | | |
470 | 483 | | |
| |||
748 | 761 | | |
749 | 762 | | |
750 | 763 | | |
| 764 | + | |
| 765 | + | |
751 | 766 | | |
752 | 767 | | |
753 | 768 | | |
| |||
821 | 836 | | |
822 | 837 | | |
823 | 838 | | |
| 839 | + | |
| 840 | + | |
824 | 841 | | |
825 | 842 | | |
826 | 843 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
115 | 116 | | |
116 | 117 | | |
117 | 118 | | |
| |||
137 | 138 | | |
138 | 139 | | |
139 | 140 | | |
140 | | - | |
141 | | - | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
142 | 145 | | |
143 | 146 | | |
144 | 147 | | |
| |||
1121 | 1124 | | |
1122 | 1125 | | |
1123 | 1126 | | |
| 1127 | + | |
| 1128 | + | |
| 1129 | + | |
| 1130 | + | |
| 1131 | + | |
| 1132 | + | |
1124 | 1133 | | |
1125 | 1134 | | |
1126 | 1135 | | |
| |||
2088 | 2097 | | |
2089 | 2098 | | |
2090 | 2099 | | |
2091 | | - | |
| 2100 | + | |
2092 | 2101 | | |
2093 | 2102 | | |
2094 | 2103 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
293 | 293 | | |
294 | 294 | | |
295 | 295 | | |
296 | | - | |
297 | | - | |
298 | | - | |
299 | | - | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
300 | 299 | | |
301 | 300 | | |
302 | 301 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
80 | | - | |
| 80 | + | |
| 81 | + | |
81 | 82 | | |
82 | 83 | | |
83 | 84 | | |
| |||
89 | 90 | | |
90 | 91 | | |
91 | 92 | | |
92 | | - | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
93 | 100 | | |
94 | 101 | | |
95 | 102 | | |
| |||
229 | 236 | | |
230 | 237 | | |
231 | 238 | | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
232 | 242 | | |
233 | 243 | | |
234 | 244 | | |
| |||
0 commit comments