Re: [RFC] Scalar Type Hinting With Casts (re-opening)
| From: | Jocelyn Fournier | Date: | Sun, 13 Jul 2014 16:09:01 +0000 |
| Subject: | Re: [RFC] Scalar Type Hinting With Casts (re-opening) | ||
| References: | 1 2 3 4 5 6 7 8 9 10 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-75424@lists.php.net to get a copy of this message | ||
Le 13/07/2014 17:51, Rowan Collins a écrit :
On 13/07/2014 16:35, Jocelyn Fournier wrote:If "type hint" is doing exactly the same than explicit cast, it should not fail on wants_array('abc'), but give a warning about the implicit cast conversion. JocelynWell, the ability to cast to an object at all is pretty wacky, since PHP has no standard base class for objects, nor any mechanism to cast to or from specific classes, etc. Perhaps this example is more appropriate: function wants_array(array $foo) { var_dump($foo); } wants_array('abc'); // Error wants_array( (array)'abc' ); // OK - parameter passed is array(0 => 'abc') As you can see, it's perfectly possible for the value to be cast, but the "type hint" does not do so, it rejects the value.That seems both inconsistent and less useful than a hybrid juggling + validation approach.Than means you find currently inconsistant than $foo = (int) 'abc'; works but not $bar = (object) 'abc'; ? :)