#23022 [Com]: Supported dereferencing array indeces on arbitrary expressions

From: Date: Fri, 23 Feb 2007 22:15:16 +0000
Subject: #23022 [Com]: Supported dereferencing array indeces on arbitrary expressions
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-109439@lists.php.net to get a copy of this message
 ID:               23022
 Comment by:       m_rayman at bigfoot dot com
 Reported By:      mfischer@php.net
 Status:           Open
 Bug Type:         Feature/Change Request
 Operating System: Any
 PHP Version:      5CVS-2003-04-02 (dev)
 New Comment:

doesn't fix the bug, but a workaround:

function array_val($array, $key) {
	return $array[$key];
}

then you can do things like:

var_dump(array_val(array('a', 'b'), 1));


Previous Comments:
------------------------------------------------------------------------

[2003-04-02 10:30:35] mfischer@php.net

Supported dereferencing array indeces on arbitrary expressions.

Currently you can only dereference array indeces on variables
directly:

$a = array('a', 'b');
var_dump($a[1]);

but this does not work

var_dump(array('a', 'b')[1]);

neither does this:

function returnArray() {
    return array('a', 'b');
}
var_dump(returnArray()[1]);

or this:

$value = ($ns == 'foo' ? $thisArray : $thatArray)[0];

------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=23022&edit=1


Thread (17 messages)

« previous php.bugs (#109439) next »