3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class B { public $var; protected $var2; protected $_var3; public function __construct($var) { $this->var = $var; $this->var2 = $var; $this->_var3 = $var; } } class A { public $class; public function __construct(B $class) { $this->class = $class; } } $b = new B('test'); $a = new A($b); echo $b->var."\n"; echo $b->var2."\n"; echo $b->_var3."\n"; echo $a->class->var."\n"; echo $a->class->var2."\n"; echo $a->class->_var3."\n"; echo $a->class->var."\n"; $b->var = 'test2'; echo $b->var."\n"; echo $b->var2."\n"; echo $b->_var3."\n"; echo $a->class->var."\n"; echo $a->class->var2."\n"; echo $a->class->_var3."\n";
based on rWGo7
Output for 7.0.0 - 7.2.0
test Fatal error: Uncaught Error: Cannot access protected property B::$var2 in /in/9P9PX:24 Stack trace: #0 {main} thrown in /in/9P9PX on line 24
Process exited with code 255.
Output for 5.3.22 - 5.6.28
test Fatal error: Cannot access protected property B::$var2 in /in/9P9PX on line 24
Process exited with code 255.