php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #35957 Array literal syntax support
Submitted: 2006-01-10 08:28 UTC Modified: 2011-11-27 12:31 UTC
Votes:25
Avg. Score:4.9 ± 0.4
Reproduced:21 of 21 (100.0%)
Same Version:10 (47.6%)
Same OS:12 (57.1%)
From: matt at matttoddphoto dot com Assigned: felipe (profile)
Status: Closed Package: *General Issues
PHP Version: 6CVS-2006-01-10 (snap) OS: Any
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: matt at matttoddphoto dot com
New email:
PHP Version: OS:

 

 [2006-01-10 08:28 UTC] matt at matttoddphoto dot com
Description:
------------
It would be lovely to be able to literally define arrays with 
simple syntax like the following:

["one", "two", "three"]

instead of the less intuitive:

array("one", "two", "three");

This would simplify creating arrays of arrays (of arrays) 
inline for functions. Also, this would help solve the 'named 
parameters' request by allowing for an associative array to be 
given simply by throwing []s in.

Reproduce code:
---------------
Here is an example just for the sake of clarity:

$validate = [$_POST['post'], ['title'=>'/[A-Za-z0-9_\?\!\.\#\&\%]+/', "text"=>'/\w*/', 'user_id'=>'/\d+/']];

This would be in opposition to:

$validate = array($_POST['post'], array('title'=>'/[A-Za-z0-9_\?\!\.\#\&\%]+/', "text"=>'/.*/', 'user_id'=>'/\d+/'));

You can see how more complex examples can get just that much more complex (the the nth degree).


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-01-10 08:36 UTC] derick@php.net
This was discussed, and rejected, many times before.
 [2011-11-27 01:08 UTC] rasmus at mindplay dot dk
This feature was implemented in PHP 5.4:

http://svn.php.net/viewvc?view=revision&revision=313641
 [2011-11-27 12:31 UTC] felipe@php.net
-Status: Wont fix +Status: Closed -Package: Feature/Change Request +Package: *General Issues -Assigned To: +Assigned To: felipe
 [2013-03-04 20:39 UTC] don at dongilbert dot net
I love that 6 years after this was originally posted, it gets accepted. It goes to 
show what PHP devs used to have to deal with.

The rate of improvement in PHP has greatly accelerated over the last few years, 
for which I am thankful.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 12:01:29 2024 UTC