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
 [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

Add a Patch

Pull Requests

Add a Pull Request

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: Thu Mar 28 19:01:29 2024 UTC