3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface Printable { public function __toString(); } class MyPrintableClass implements Printable { public $myNumericProperty; public function __construct() { $this->myNumericProperty = 10; } public function __toString() { return 'My numeric property is ' . $this->myNumericProperty; } } function printSomething(string $printable) { echo $printable; } printSomething(new MyPrintableClass()); printSomething("You can't print a real sting"); printSomething(1234); printSomething(1.2); printSomething(true);
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 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 10You can't print a real sting12341.21
Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40
Catchable fatal error: Argument 1 passed to printSomething() must be an instance of string, instance of MyPrintableClass given, called in /in/WddK6 on line 23 and defined in /in/WddK6 on line 19
Process exited with code 255.

preferences:
261.25 ms | 402 KiB | 376 Q