On 07/12/2012 09:46 AM, Stas Malyshev wrote:
> Hi!
> 
>> For non-interchangeable types it is already strict by definition. I
>> don't see a problem with type hints that make life easier on both the
>> caller (by generating better error messages) and the callee (by having
>> to write less boilerplate type verification code).
> 
> It doesn't make the life of the caller easier. On the contrary, it makes
> each call into a minefield - will it blow up with a system-level error
> when you call it? Added bonus of this one is that there's no sure way to
> check for it - at least for callable we had is_callable, here we just
> have to add boilerplate code for every call. And good luck making them
> handle it in an unified way - since it's not library code, then probably
> will do each different thing, and about 50% of places will forget it or
> not know downstream inserted this surprise into the execution stream.

For non-interchangeable types the code is going to blow up anyway. If
you pass a MySQL resource to a function that takes a callable and that
function does $arg(); the result is a non-catchable fatal error:

Fatal error: Function name must be a string

Compare to adding 'callable':

Catchable fatal error: Argument 1 passed to func() must be callable,
resource given

This gives quite a bit more info since we now know that it was an
argument and specifically which argument it was, what its type was and
what it should have been vs. having a fatal from somewhere deep in the
function itself. So I disagree with you on it not making life easier for
the caller in this specific case where there is no way for the type to
be coerced into something that makes sense.

-Rasmus

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to