|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #14763 Make [] of arrays readable
Submitted: 2001-12-30 04:29 UTC Modified: 2001-12-30 10:29 UTC
From: linus at mccabe dot nu Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 4.1.1 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: linus at mccabe dot nu
New email:
PHP Version: OS:


 [2001-12-30 04:29 UTC] linus at mccabe dot 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.



Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2001-12-30 04:45 UTC]
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 09:42 UTC] linus at mccabe dot nu
$b = $a[] 
would be
$b = $a[count($a)-1], not $b = $a[count($a)]

 [2001-12-30 10:29 UTC]
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.

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Jul 13 03:02:22 2024 UTC