Bug #14763 Updated: Make [] of arrays readable
| From: | georg@php.net | Date: | Sun, 30 Dec 2001 15:29:36 +0000 |
| Subject: | Bug #14763 Updated: Make [] of arrays readable | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-75356@lists.php.net to get a copy of this message | ||
ID: 14763
Updated by: georg
Reported By: linus@mccabe.nu
Old Status: Open
Status: Bogus
Bug Type: Feature/Change Request
Operating System:
PHP Version: 4.1.1
New Comment:
In first case, when you write to the array "[]" is a
synonym for count($array)
In second case, if you read from array "[]" should be
(your suggestion/feature request) a synonym for
count($array) - 1.
Sorry, but this is not consistent.
Previous Comments:
------------------------------------------------------------------------
[2001-12-30 09:42:34] linus@mccabe.nu
$b = $a[]
would be
$b = $a[count($a)-1], not $b = $a[count($a)]
------------------------------------------------------------------------
[2001-12-30 04:45:50] georg@php.net
There is no need to make an array '$a[]' readable.
$a[] = "foo";
is short for
$a[count($a)] = "foo";
if $a[] would be readable, result would be always NULL:
$b = $a[] ( which would be the same as $a[count($a)])
------------------------------------------------------------------------
[2001-12-30 04:29:01] linus@mccabe.nu
Currently in php, you can append to a variable by using the [] form:
$a[] = 'a';
$a[] = 'b';
It would be great if you could also read an array in the same manner, ie:
$lastadded = $a[];
which would be equivalent to
$lastadded = $a[count($a)-1];
which is what you have to do today.
/linus
------------------------------------------------------------------------
Edit this bug report at http://bugs.php.net/?id=14763&edit=1