3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php declare(strict_types=1); class Foo { private $x; public function setX($x) : Foo { $this->x = $x; return $this; } public function getX() { return $this->x; } } function test($class) { if (class_exists($class)) { return new $class(); } return null; } $x = test('Fo')->setX('test'); var_dump($x->getX());
based on KPOIA
Output for 7.0.0 - 7.2.0
Fatal error: Uncaught Error: Call to a member function setX() on null in /in/pGNnT:29 Stack trace: #0 {main} thrown in /in/pGNnT on line 29
Process exited with code 255.
Output for 5.3.20 - 5.6.28
Warning: Unsupported declare 'strict_types' in /in/pGNnT on line 3 Parse error: syntax error, unexpected ':', expecting ';' or '{' in /in/pGNnT on line 8
Process exited with code 255.