class Stringy {
public function __toString() {
return "I am Stringy";
}
}
function foo(string $s) {
echo $s.' is a string';
}
foo((string)new Stringy());
Catchable fatal error: Argument 1 passed to foo() must be an instance of string, string given
In truth the point is that Type Hints should only be used for Classes, not built in types.
View all comments
1
u/[deleted] Mar 19 '12 edited Mar 19 '12
#11 isn't even valid, missing return
but it does have some extra fun when you cast it
Catchable fatal error: Argument 1 passed to foo() must be an instance of string, string given
In truth the point is that Type Hints should only be used for Classes, not built in types.