3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface Printable { public function __toString(); } class MyPrintableClass { public $myNumericProperty; public function __construct() { $this->myNumericProperty = 10; } public function __toString() { return 'My numeric property is ' . $this->myNumericProperty; } } function printSomething(string $printable) { echo $printable; } $printable = new MyPrintableClass(); printSomething((string) $printable); printSomething("a real string"); printSomething((string)1234); printSomething((string)1.2); printSomething((string)true);
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.6
My numeric property is 10a real string12341.21
Output for 5.4.1 - 5.4.45, 5.5.24 - 5.5.35, 5.6.8 - 5.6.28
Catchable fatal error: Argument 1 passed to printSomething() must be an instance of string, string given, called in /in/UdIis on line 24 and defined in /in/UdIis on line 19
Process exited with code 255.

preferences:
168.13 ms | 402 KiB | 227 Q