Commit 1181775
authored
Fixing parser error when encountering complex variables. (#26)
Fixes #18
In PhpParser, the $node->name property of a Node\Expr\Variable can be either:
- a string (for simple variables like $foo)
- or an Expr node (usually another Variable or an expression, for complex variables like ${$bar} or variable
variables)
This is because PHP allows variable variables and complex expressions as variable names, so the parser represents them as objects rather than plain strings. Always check the type before using it as an array key.
When `$node->name is an object (not a string)`, it represents complex or variable variables (like `${$foo}`) in PHP. These cases are rare in typical code and are challenging to statically analyze. For metrics like variable counting, they are usually not relevant or are intentionally skipped, since you cannot reliably determine the variable name at parse time.1 parent e31325b commit 1181775
File tree
2 files changed
+53
-4
lines changed- src/PhpParser
- tests/Unit/PhpParser
2 files changed
+53
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
194 | 194 | | |
195 | 195 | | |
196 | 196 | | |
197 | | - | |
| 197 | + | |
198 | 198 | | |
199 | 199 | | |
200 | 200 | | |
| |||
208 | 208 | | |
209 | 209 | | |
210 | 210 | | |
211 | | - | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
212 | 233 | | |
213 | | - | |
214 | | - | |
| 234 | + | |
215 | 235 | | |
216 | 236 | | |
217 | 237 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
67 | 96 | | |
0 commit comments