You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 727dcd4
Browse filesBrowse the repository at this point in the historyBrowse files
Report inheritance cycles with a rule instead of a reflection error
A class that extends itself, interfaces that extend each other and
traits that use each other cannot be declared in PHP. A class on a
parent class cycle now has no parent instead of throwing
CircularReference, and a trait inside a trait on a cycle processes only
the traits reflection says it uses. CircularInheritanceRule reports the
cycle on each of its members, at level 0.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: .github/workflows/e2e-tests.yml
+22-3Lines changed: 22 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -1352,12 +1352,13 @@ jobs:
1352
1352
OUTPUT=$(../bashunit -a exit_code "0" "../../bin/phpstan analyse -vvv --error-format raw")
1353
1353
echo "$OUTPUT"
1354
1354
../bashunit -a not_contains 'not found' "$OUTPUT"
1355
-
# A reflection error, here a class that extends itself, still keeps the result cache from
1356
-
# being saved.
1355
+
# A class that extends itself is reported by a rule and is not a reflection error, so the
1356
+
# result cache is saved.
1357
1357
cp loop/Loop.php src/Loop.php
1358
1358
OUTPUT=$(../bashunit -a exit_code "1" "../../bin/phpstan analyse -vvv --error-format raw")
1359
1359
echo "$OUTPUT"
1360
-
../bashunit -a contains 'Result cache was not saved because of non-ignorable exception: Reflection error: Circular reference' "$OUTPUT"
1360
+
../bashunit -a contains 'Loop.php:5:Class ResultCacheE2EParseError\Loop extends itself.' "$OUTPUT"
1361
+
../bashunit -a contains 'Result cache is saved.' "$OUTPUT"
1361
1362
- script: |
1362
1363
cd e2e/result-cache-internal-error
1363
1364
composer dump-autoload
@@ -1367,6 +1368,24 @@ jobs:
1367
1368
../bashunit -a contains 'Internal error: The rule crashed.' "$OUTPUT"
1368
1369
../bashunit -a contains 'Result cache was not saved' "$OUTPUT"
1369
1370
test ! -f tmp/resultCache.php
1371
+
- script: |
1372
+
cd e2e/result-cache-circular-inheritance
1373
+
# src/First.php, src/Second.php and src/Third.php extend each other in a cycle. src/TraitA.php
1374
+
# uses TraitB, which uses TraitC, without a cycle.
1375
+
OUTPUT=$(../bashunit -a exit_code "1" "../../bin/phpstan analyse -vv --error-format raw")
1376
+
echo "$OUTPUT"
1377
+
../bashunit -a contains 'First.php:5:Class ResultCacheE2ECircularInheritance\First extends ResultCacheE2ECircularInheritance\Second, which extends ResultCacheE2ECircularInheritance\Third, which extends ResultCacheE2ECircularInheritance\First.' "$OUTPUT"
1378
+
../bashunit -a not_contains 'TraitA' "$OUTPUT"
1379
+
# Breaking the cycle in src/Third.php has to re-analyse src/First.php, although a class on a
1380
+
# cycle has no parents and the file depends only on its direct parent otherwise.
1381
+
cp patched/Third.php src/Third.php
1382
+
# src/TraitC.php now uses TraitA, which closes a cycle. A trait declaration is not analysed on
1383
+
# its own, so src/TraitA.php depends on the traits it uses only through the rule.
1384
+
cp patched/TraitC.php src/TraitC.php
1385
+
OUTPUT=$(../bashunit -a exit_code "1" "../../bin/phpstan analyse -vv --error-format raw")
1386
+
echo "$OUTPUT"
1387
+
../bashunit -a not_contains 'First.php' "$OUTPUT"
1388
+
../bashunit -a contains 'TraitA.php:5:Trait ResultCacheE2ECircularInheritance\TraitA uses ResultCacheE2ECircularInheritance\TraitB, which uses ResultCacheE2ECircularInheritance\TraitC, which uses ResultCacheE2ECircularInheritance\TraitA.' "$OUTPUT"
0 commit comments