Hi.
At the moment we can type hint array, classes, interfaces, callable, etc.
As PHP is loosely typed and has type juggling thinking of (or at least
trying to get PHP to enforce) a particular type (string, int, float,
boolean) would be the wrong way to go - too many different behaviours
(block if not a suitable type, block if not a suitable castable value,
nonblocking with auto juggling, etc.). But if we consider that type
juggling is the domain of the type 'scalar', then this would/could act as a
suitable hinter.
If a method has been designed to accept a scalar, there is nothing to stop
the passing in of a resource, callable, closure or object, etc.
But with the type hint, in my head, it is now no different to any other
type hint.
scalar, callable, interface, class, array (and others I'm sure).
This isn't about trying to cast the value to a type - PHP is intrinsically
loosely typed and that is core to everything. But as the core can easily
tell an array from a callable, then a scalar would seem to fit right in.
And if we can have scalar type hinting, scalar return type hinting
would/should also be possible.
Is this a feasible option?
--
Richard Quadling
Twitter : @RQuadling
EE : http://e-e.com/M_248814.html
Zend : http://bit.ly/9O8vFY