3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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);
based on QTd0b
Output for 7.0.0 - 7.2.0
My numeric property is 10You can't print a real sting12341.21
Output for 5.3.18 - 5.6.28
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.