php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #41268 Access array member without variable
Submitted: 2007-05-03 12:06 UTC Modified: 2007-05-03 12:15 UTC
From: viktor_b_68 at passagen dot se Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 5.2.1 OS:
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: viktor_b_68 at passagen dot se
New email:
PHP Version: OS:

 

 [2007-05-03 12:06 UTC] viktor_b_68 at passagen dot se
Description:
------------
When you get a reference to an array, by a function, there is no way to access any certain member of the array.
With this function given:

<?php
function get_array()
{
	return array("foo" => "FOO", "bar" => "BAR");
}
?>

there is no way to do:
	
<?php print get_array()["foo"] ?>

You have to do like this:

<?php
$array = get_array();
print $array["foo"];
?>

There should be a way to access a member of the array in only one expression, without the need for assigning a variable.
Either by using the first syntax above, or if you don't like the looks of it, maybe a function like this:

<?php print array_value(get_array(), "foo") ?>


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-05-03 12:15 UTC] johannes@php.net
This was discussed multiple times before and was rejected. Please check the archives of php-internals to get further details.

btw. You can easily implement your array_value() function yourself. We won't add simple array functions.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 17:01:58 2024 UTC