Casting in list()
| From: | hakre | Date: | Sun, 06 Jan 2013 01:15:40 +0000 |
| Subject: | Casting in list() | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-64589@lists.php.net to get a copy of this message | ||
I just run over this a few times lately (it is a bit indirect because of not having much logic in
the overall syntax, but probably not that bad), for PHPs list() construct I think it would be nice
being able to cast the assignments on the fly:
list((string) $name) = array(new SplFileInfo(__FILE__));
(yes this example is not very creative but should be enough for a brief illustration).
Would this be possible? I know some folks do not like list, but on the other hand, things like these
don't work in PHP:
$name = (string) ($array ? : [new SplFileInfo(__FILE__)])[0]
and having casting list list() can be handy then.
Is this hard to add to core PHP?
-- hakre