Re: Type hinting
| From: | Hannes Magnusson | Date: | Sat, 22 May 2010 22:01:04 +0000 |
| Subject: | Re: Type hinting | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-48398@lists.php.net to get a copy of this message | ||
On Sat, May 22, 2010 at 22:39, Lukas Kahwe Smith <mls@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.
> can we please just stop calling a something a "type hinting" system, which leads to a
> catchable fatal error when the type does not strictly match? thats a very misleading euphemism. its
> simply strict typing, it has nothing to do with hinting.
>
It definitely isn't strict either:
$ php -r 'function errh() {} set_error_handler("errh",
E_RECOVERABLE_ERROR); function bar(foo $x) {echo "hello world\n";}
bar(1);'
hello world
-Hannes