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