Re: [RFC] Scalar Type Hinting With Casts (re-opening)

From: Date: Mon, 14 Jul 2014 17:31:22 +0000
Subject: Re: [RFC] Scalar Type Hinting With Casts (re-opening)
References: 1 2 3 4 5 6 7 8 9 10 11 12  Groups: php.internals 
Request: Send a blank email to internals+get-75498@lists.php.net to get a copy of this message
Zeev,

>> And passing 'hello' to a function type hinted as int? Will people really
>> expect
>> that to become a 0, with a mild warning they may not even have enabled?
>
> I'd say absolutely yes, if they're PHP developers that's exactly what
> they'd
> expect.  After all, if you use 'hello' today in any integer context in PHP,
> explicit or implicit, that's exactly how it will behavior across the
> language.

Compare:

$ php -r 'var_dump(substr("abc", "1"));'
string(2) "bc"

$ php -r 'var_dump(substr("abc", "1sf"));'
PHP Notice:  A non well formed numeric value encountered in Command
line code on line 1
string(2) "bc"

$ php -r 'var_dump(substr("abc", "apple"));'
PHP Warning:  substr() expects parameter 2 to be long, string given in
Command line code on line 1
NULL

So it's not really how it behaves across the language (especially
since the common paradigm is not run the function if zpp fails, which
it will when passing "apple" to a function expecting an int).


Thread (250 messages)

« previous php.internals (#75498) next »