Re: Type hinting
| From: | Zeev Suraski | Date: | Thu, 27 May 2010 11:14:30 +0000 |
| Subject: | Re: Type hinting | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-48507@lists.php.net to get a copy of this message | ||
At 13:59 27/05/2010, Ilia Alshanetsky wrote:
Zeev, Auto-conversion does not validate input to the function/method, it merely obfuscates the "wrong" input by converting it to desired type resulting in a potentially un-expected value. I must say I am completely against the auto-conversion hint idea.All of PHP is built on that kind of conversion. See Brian Moon's email for a detailed instructions. BTW - even if strict type checking was implemented, do you truly think people won't simply cast their inputs to make PHP shutup about "42" not being a valid int? Let me assure you, they would. You'd gain nothing - as a matter of fact you'd lose out a bit since "abc" strings or arrays will happily cast into (int), while with our proposed solution - they won't.
As far as your example goes consider a function that expects a boolean, but instead gets an int/string/float, which in nearly all cases will result in TRUE. Which is not the desired outcome.Again, I don't think you can hope for anybody doing anything but (bool) cast before calling the function. And anyway, how is that different from if ($foo)? or while($bar)? Why would functions arguments behave any differently? If you care explicitly about zval.type being boolean, use is_bool(). Zeev