3v4l.org

run code in 300+ PHP versions simultaneously
<?php class A { } class B extends A { public self $instOfSelf; public parent $instOfParent; } $b = new B(); $b->instOfParent = new B(); # Allowed var_dump($b); $b->instOfParent = new A(); # Also allowed var_dump($b); $b->instOfSelf = new B(); # Allowed var_dump($b); $b->instOfSelf = new A(); # ERROR var_dump($b);
Output for git.master, git.master_jit, rfc.property-hooks
object(B)#1 (1) { ["instOfSelf"]=> uninitialized(self) ["instOfParent"]=> object(B)#2 (0) { ["instOfSelf"]=> uninitialized(self) ["instOfParent"]=> uninitialized(parent) } } object(B)#1 (1) { ["instOfSelf"]=> uninitialized(self) ["instOfParent"]=> object(A)#3 (0) { } } object(B)#1 (2) { ["instOfSelf"]=> object(B)#2 (0) { ["instOfSelf"]=> uninitialized(self) ["instOfParent"]=> uninitialized(parent) } ["instOfParent"]=> object(A)#3 (0) { } } Fatal error: Uncaught TypeError: Cannot assign A to property B::$instOfSelf of type self in /in/n820F:21 Stack trace: #0 {main} thrown in /in/n820F on line 21
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
15.53 ms | 402 KiB | 8 Q