3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php trait FooBarTrait { /** * @var string */ private $value; /** * {@inheritdoc} */ public function setValue(string $value): void { $this->value = $value; } /** * {@inheritdoc} */ public function getValue(): string { return $this->value; } } interface Bar { /** * @param string $value */ public function setValue(string $value): void; /** * @return string */ public function getValue(): string; } class Foo implements Bar { use FooBarTrait; } $foobar = new Foo(); $foobar->setValue('bob'); echo $foobar->getValue();
Output for hhvm-3.21.3 - 3.22.0, 7.1.0 - 7.3.0alpha1
bob
Output for 7.0.30
Fatal error: Uncaught TypeError: Return value of Foo::setValue() must be an instance of void, none returned in /in/bTZgQ:16 Stack trace: #0 /in/bTZgQ(46): Foo->setValue('bob') #1 {main} thrown in /in/bTZgQ on line 16
Process exited with code 255.
Output for hhvm-3.18.5
Fatal error: Uncaught TypeError: Value returned from method Foo::setValue() must be of type void, null given in /in/bTZgQ:16 Stack trace: #0 /in/bTZgQ(46): Foo->setValue() #1 {main}
Process exited with code 255.
Output for 5.6.30
Parse error: syntax error, unexpected ':', expecting ';' or '{' in /in/bTZgQ on line 13
Process exited with code 255.