3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class A { private $priv; function setPrivA( $x ) { $this->priv = $x; } } class B extends A { private $priv; function setPrivB($foo) { $this->priv = $foo; } } class C extends A { function accessOther( $a ) { return $a->priv; } } $b = new B; $b->setPrivA('foo'); $b->setPrivB('bar'); var_dump( $b ); $c = new C; $c->priv = 'baz'; var_dump( $c ); var_dump( $c->accessOther( $b ) );
based on 5iT1L
Output for 7.0.0 - 7.2.6
object(B)#1 (2) { ["priv":"B":private]=> string(3) "bar" ["priv":"A":private]=> string(3) "foo" } object(C)#2 (2) { ["priv":"A":private]=> NULL ["priv"]=> string(3) "baz" } Fatal error: Uncaught Error: Cannot access private property B::$priv in /in/nq2k5:21 Stack trace: #0 /in/nq2k5(33): C->accessOther(Object(B)) #1 {main} thrown in /in/nq2k5 on line 21
Process exited with code 255.
Output for hhvm-3.15.4
object(B)#1 (2) { ["priv":"B":private]=> string(3) "bar" ["priv":"A":private]=> string(3) "foo" } object(C)#2 (2) { ["priv":"A":private]=> NULL ["priv"]=> string(3) "baz" } Fatal error: Uncaught Error: Cannot access private property B::$priv in /in/nq2k5:21 Stack trace: #0 /in/nq2k5(33): C->accessOther() #1 {main}
Process exited with code 255.
Output for 5.6.0 - 5.6.30
object(B)#1 (2) { ["priv":"B":private]=> string(3) "bar" ["priv":"A":private]=> string(3) "foo" } object(C)#2 (2) { ["priv":"A":private]=> NULL ["priv"]=> string(3) "baz" } Fatal error: Cannot access private property B::$priv in /in/nq2k5 on line 21
Process exited with code 255.