On 24 March 2020 13:32:35 GMT+00:00, Enno Woortmann <enno.woortm...@web.de> 
wrote:
> How about adding some syntactic sugar and
>allow type casting inside the detructuring expression?
>
>$data = "foo:*:1023:1000::/home/foo:/bin/sh";
>[$user, $pass, (int) $uid, (int) $gid, $gecos, $home, $shell] =
>explode(":", $data);


On the one hand, this seems fairly straightforward, and although casts wouldn't 
normally appear on the left side of an expression, the intent is pretty clear.

On the other hand, this is exactly the kind of thing where strict_types=1 makes 
things worse - you'll actually get *better* error output if you use 
strict_types=0 and pass the string to a function marked as requiring int. By 
forcing a cast, you're actually silencing the error, and turning all 
unrecognised values to 0.

If the desire is for stricter type handling, we probably need stricter casts, 
perhaps using different syntax like (int!) rather than just more places to put 
the existing ones.


Regards,

-- 
Rowan Tommins
[IMSoP]

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

Reply via email to