<?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);
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.