Commit ee3c15d
committed
removed return type from Container::__call() again [Closes nette/utils#338]
The native `: mixed` return type was accidentally reintroduced on
Container::__call() by 7cbe717 ("added missing native types"),
reviving an incompatibility that had already been fixed once for
nette/utils#315 (commit 40afa80).
Nette\SmartObject::__call() in nette/utils intentionally declares no
native return type (it stays untyped for BC). As long as nobody
re-applies the trait, narrowing the inherited untyped __call() to
`: mixed` is allowed and everything loads fine - which is why the test
suite and Forms' own classes are unaffected.
The fatal error appears only when a subclass extends Form/Container AND
re-applies the SmartObject trait, e.g.:
class MyForm extends Nette\Forms\Form { use Nette\SmartObject; }
Then the trait's untyped __call() overrides the already-typed
__call(): mixed, which PHP rejects as removing a return type:
Declaration of Nette\SmartObject::__call(string $name, array $args)
must be compatible with
Nette\Forms\Container::__call(string $name, array $args): mixed
Re-applying SmartObject on top of a class that already has it is an
unusual, unexpected pattern, so the regression slipped through - but it
happens in the wild (e.g. via downstream component classes), breaks on
all PHP 8.1-8.5, and matches the report that 3.2.8 works but 3.2.9 does
not. Dropping the native return type (keeping it in phpDoc) restores
compatibility. A regression test covering the trait combination is added.1 parent 1b7878e commit ee3c15d
2 files changed
Lines changed: 30 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
604 | 604 | | |
605 | 605 | | |
606 | 606 | | |
607 | | - | |
608 | | - | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
609 | 612 | | |
610 | 613 | | |
611 | 614 | | |
| |||
| 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 | + | |
0 commit comments