2010/8/11 Ilia Alshanetsky <i...@prohost.org>:
> I think that weak type-hinting defeats the whole purpose of the
> feature and I would rather not have it than have a non-obvious
> implementation.
>
> -1
>

I would like to point out an argument, posted in the "Typehints (was
Re: [PHP-DEV] Annoucing PHP 5.4 Alpha 1)" thread by Jonathan
Bond-Caron, quoting:
"It's only consistent in the function declarations but *completely*
inconsistent with how the rest of the language works."

He took the words out of my mouth.

The auto-convert feature only touches the idea that 1 => "1", "1" => 1
conversions should take place automatically. In the case of "abcd" =>
0 we emit an error message. As it was mentioned in the RFC, the idea
is not only to make type hint's this way, but _also_ to change the
language conversion rules acordingly to match the type hinting
auto-conversion rules. That way the conversion rules are made more
strict and type hints get some freedom instead of going into E_FATAL
everytime a developer misses string to int (and other similiar)
conversion in the code before passing data to objects/functions/API.
The conversions don't just go completly silent if inapropriate value
is passed to the function/method witch can't be converted
transparently to the required type. It gives you the error message and
it's your choise to ignore it or fix it. Strict type hintng will just
bring tons of code that does:
settype('integer', $total);
settype('integer', $per_page);
settype('integer', $page);
pager($page, $total, $per_page);

It will have to be written to make sure the variables have the right
type. Especially $page, witch usually comes via $_GET. Instead of just
checking for is_numeric now we have also to convert the type.

I just have an empression that you don't write much PHP code or you
work on very big and highly sophisticated projects, where the
situation is different. You leaving out the majority of PHP code
written for the middle and small scale projects, witch usually done by
far more simplier tools, sometimes even just using the plain old PHP
without a framework (and yes, sometimes it's just faster that way!).

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

Reply via email to