| crodas | yes | 2012-03-07 21:05 |
| dm | yes | 2014-05-06 21:15 |
| irker | yes | 2011-12-14 11:28 |
| jwage | yes | 2011-12-28 03:50 |
| kassner | yes | 2011-12-27 13:50 |
| klaussilveira | yes | 2011-12-27 12:33 |
| kriscraig | yes | 2012-02-20 19:17 |
| stas | yes | 2012-02-26 09:03 |
| tyrael | yes | 2011-12-27 09:37 |
| weierophinney | yes | 2012-01-03 17:07 |
Copied from wiki.php.net, last synchronized Oct 13, 2026 11:52 UTC
A little improvement to make things consistent.
Base on feature request: https://bugs.php.net/bug.php?id=60408:
Please add array constructor dereferencing support
like JavaScript, C# and all languages excluding PHP 5.4
<?php
$i=0;
print(array('pa','th')[$i++]); // pa
print(['wa','ss'][$i++]); // ss
?>
I wrote a patch to make php support const array/string dereferencing. After the patch, the following script works:
echo array(1, 2, 3)[0]; //output 1
echo "foobar"[2]; //output o
echo "foobar"["foo"][0] // output f
echo [1,3,4][2]; //output 4
Vote: do you think it is okey to apply this to TRUNK(not 5.4)? — yes: 10 · no: 0 (closed)