On Tue, Oct 16, 2012 at 12:55 PM, Stas Malyshev <smalys...@sugarcrm.com> wrote:
>> Last thing: I agree with Clint and you. If it was early checked, it
>> would be better. But the current type hinting is far better than nothing
>> at all. Yes, we can't "lint" it, but it was pretty useful a big number
>
> No, it's not better. Having code that can randomly fail with one error
> message is not better than having code that can randomly fail with
> another error message. It is more or less the same.
It actually makes a very big difference just how exactly the code
fails. Whether it fails at the point where you assign an invalid value
to a property or whether it fails 50 frames down the line where that
property is then read and you don't really know where that value came
from.

The extreme example of just how much of a difference it can make is
C++ template metaprogramming. If you ever used a heavily templated
library in C++ you'll know the pain of looking at a 400 line long
template trace and trying to figure just where you went wrong. It's
obviously not that extreme in PHP, but it's always better to get a
directly relevant error message, rather than the error popping up
somewhere down the line (or if you're very unlucky not turning up at
all).

> It can actually be
> worse since it'd introduce more boliterplate checks in wrong places
> (i.e., you'd have to check every variable for correct type before
> assigning it to typed property)
I see this argument crop up with every typehint discussion and just
don't understand it at all. Why would you want to check the variable
type everywhere? You just assign it and if it doesn't work, then you
get an error. Just like it should be. I mean, do you seriously check
the type of every function argument because you fear the parameter
type hints that much? Doesn't make sense to me.

> and does not provide any control over
> how the situation when something is wrong is going to be handled.
That's not related to typehints really. PHP just does not have a
usable mechanism for recovering from error situations. You can
register an E_RECOVERABLE error handler and let the code continue, but
it's all very inconvenient. Also, I never had a situation where I
wanted to recover from a failed parameter type check. I don't see how
property type checks are different.

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

Reply via email to