3v4l.org

run code in 300+ PHP versions simultaneously
<?php trait toArray { public function toArray() { return get_object_vars($this); } public function fromArray(array $properties) { foreach ($properties as $key => $value) { if (method_exists($this, 'set' . ucfirst($key))) { $this->{'set' . ucfirst($key)}($value); } } } } interface BazInterface { } class Bazz implements BazInterface { } interface FooInterface { public function add(BazInterface $baz); public function toArray(); public function fromArray(array $properties); } class Foo implements FooInterface { use toArray; private $bar; private $baz; public function setBar($bar) { $this->bar = $bar; return $this; } public function setBaz($baz) { $this->baz = $baz; return $this; } } $foo = new Foo; $foo->fromArray(['bar' => 'boo', 'baz' => 'test']); $fooArray = $foo->toArray(); var_export($fooArray);
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Fatal error: Class Foo contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (FooInterface::add) in /in/lkjhC on line 36
Process exited with code 255.
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Fatal error: Class Foo contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (FooInterface::add) in /in/lkjhC on line 36
Process exited with code 255.
Output for 5.4.1 - 5.4.45, 5.5.24 - 5.5.35, 5.6.7 - 5.6.28
Fatal error: Class Foo contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (FooInterface::add) in /in/lkjhC on line 53
Process exited with code 255.

preferences:
189.74 ms | 402 KiB | 229 Q