3v4l.org

run code in 300+ PHP versions simultaneously
<?php class ParentClassWithToStringMixedReturn { public function __toString() { return 'a'; } } class WithParentMixedReturn extends ParentClassWithToStringMixedReturn { public function __toString(): string { return 'value'; } } class Consumer extends WithParentMixedReturn { public function __toString() { return 'value'; } } echo (new Consumer());
Output for 8.2.28 - 8.2.29, 8.3.5 - 8.3.26, 8.4.5 - 8.4.13
value
Output for 7.4.33
Fatal error: Declaration of Consumer::__toString() must be compatible with WithParentMixedReturn::__toString(): string in /in/kdcEh on line 21
Process exited with code 255.

preferences:
58.77 ms | 407 KiB | 5 Q