Le 13/07/2014 17:51, Rowan Collins a écrit :
On 13/07/2014 16:35, Jocelyn Fournier wrote:
That seems both inconsistent and less useful than a hybrid juggling +
validation approach.
Than means you find currently inconsistant than
$foo = (int) 'abc';
works but not
$bar = (object) 'abc';
? :)
Well, the ability to cast to an object at all is pretty wacky, since PHP
has no standard base class for objects, nor any mechanism to cast to or
from specific classes, etc.
Perhaps this example is more appropriate:
function wants_array(array $foo) { var_dump($foo); }
wants_array('abc'); // Error
wants_array( (array)'abc' ); // OK - parameter passed is array(0 => 'abc')
As you can see, it's perfectly possible for the value to be cast, but
the "type hint" does not do so, it rejects the value.
If "type hint" is doing exactly the same than explicit cast, it should
not fail on wants_array('abc'), but give a warning about the implicit
cast conversion.
Jocelyn
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php