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) { $obj = new $class(); if (is_object($obj)) { return $obj; } return null; } $x = test('Fo')->setX('test'); var_dump($x->getX());
based on cq1oB
Output for 7.0.0 - 7.3.1
Fatal error: Uncaught Error: Class 'Fo' not found in /in/KPOIA:22 Stack trace: #0 /in/KPOIA(31): test('Fo') #1 {main} thrown in /in/KPOIA on line 22
Process exited with code 255.
Output for 5.3.20 - 5.6.28
Warning: Unsupported declare 'strict_types' in /in/KPOIA on line 3 Parse error: syntax error, unexpected ':', expecting ';' or '{' in /in/KPOIA on line 8
Process exited with code 255.