At 01:01 23/05/2010, Hannes Magnusson wrote:
On Sat, May 22, 2010 at 22:39, Lukas Kahwe Smith <m...@pooteeweet.org> wrote:
>
> On 22.05.2010, at 18:30, Josh Davis wrote:
>
>> As you wrote, you worked on PHP's _type system_ which is dynamic,
>> really cool, juggles strings with ints and what not. However, the
>> topic here is the _type hinting system_. As far as I know, there's no
>> "weak" type hinting; if a method signature hints for an array and is
>> given an integer, it throws a catchable fatal error. Therefore, as a
>> user, what I am familiar to is a strict _type hinting system_.
>> Anything else would feel inconsistent to me.


I agree. function foo(array $x) {} foo(123); doesn't cast int(123) to
array(123) so introducing different meaning for scalar types feels
very very wrong.

You're ignoring one simple fact - in PHP, scalar types are interchangeable. Unlike array->scalar which has always been a corner case and a sketchy one (and I said numerous times that had I rewrote the language now, array->scalar conversion would have probably resulted in an error) - string->number, number->string, string->boolean conversions are a cornerstone of the language. If you don't like the fact that PHP's scalar types are interchangeable - you're in the wrong language!

In terms of consistency, the difference between array type hinting and scalar type hinting you allude to is negligible in comparison to the inconsistency with, well, just about every other part of the language - operators, control structures and built-in functions (expecting sqrt("64") to fail, since sqrt() expects a number? expecting if (7) to fail, since it expects a boolean?). Auto-converting type hinting extends the same semantics available to internal functions (through zend_parse_parameters()) to userland functions. That consistency is by far the most important IMHO.

Zeev

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

Reply via email to