Re: Type hinting
| From: | Christian Schneider | Date: | Thu, 10 Jun 2010 12:12:21 +0000 |
| Subject: | Re: Type hinting | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-48720@lists.php.net to get a copy of this message | ||
Zeev Suraski wrote:
> That's exactly what I had in mind. Have E_TYPE off by default and
> implement it throughout PHP - instead of just type hints.
>
>> for example:
>> $foo = 0;
>> $foo += (int)'123abc'; // no error
>> $foo += '123abc'; // E_TYPE
Out of curiosity: What would you do with the E_TYPE on the last one?
1) Log it: What for?
2) Abort the script: Why?
3) Silence it with explicit casting: Why?
4) Look at the code and find out X: What is X?
My guess is that it is theoretically useful if you ensure that all your
normal code is E_TYPE-free and user provided input could trigger E_TYPE
which would require special code to be added in that case to avoid
future E_TYPE.
One biggy for me: E_TYPE should not slow down PHP if one is not
interested in it. I think there was a discussion about making ignored
E_* (almost) performance neutral but I don't think that's implemented
yet, right? We patched away E_NOTICE warnings in the PHP source because
we're not interested in access to undefined variables and I wouldn't
want to have to do something similar for E_TYPE.
- Chris