3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class Foo { private $bar; public function getBar() { return $this->bar; } public function setBar($bar) { $this->bar = $bar; } } class Baz { $this->container = []; public function add(Foo $foo) { $this->container[] = $foo; } public function getFirstOrDefault() { return isset($this->container[0]) ? $this->container[0] : null; } } $foo = new Foo(); $foo->setBar('baz'); $baz = new Baz(); $baz->add($foo); echo $baz->getFirstOrDefault()->getBar();
Output for 5.4.0 - 5.5.12
Parse error: syntax error, unexpected '$this' (T_VARIABLE), expecting function (T_FUNCTION) in /in/hJPH1 on line 11
Process exited with code 255.
Output for 5.3.0 - 5.3.28
Parse error: syntax error, unexpected T_VARIABLE, expecting T_FUNCTION in /in/hJPH1 on line 11
Process exited with code 255.