3v4l.org

run code in 300+ PHP versions simultaneously
<?php class A { private $a; public function __construct($a) { $this->a = $a; } } class B extends A { /** * Use php's magic method to enforce immutability */ public function __set($property, $value) { throw new RuntimeException(self::class . ' is immutable'); } } $a = new A(1); $b = new B(2); $a->b = $b; var_dump($a); try { $b->c = 3; } catch (RuntimeException $re) { var_dump($b); }
Output for git.master, git.master_jit, rfc.property-hooks
Deprecated: Creation of dynamic property A::$b is deprecated in /in/RC1Sk on line 27 object(A)#1 (2) { ["a":"A":private]=> int(1) ["b"]=> object(B)#2 (1) { ["a":"A":private]=> int(2) } } object(B)#2 (1) { ["a":"A":private]=> int(2) }

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:
126.48 ms | 406 KiB | 5 Q