1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
--TEST--
Testing array dereference
--FILE--
<?php
error_reporting(E_ALL);
function a() {
return array(1,array(5));
}
var_dump(a()[1][0]); // int(5)
function b() {
return array();
}
var_dump(b()[0]); // Notice: Undefined offset: 0
class foo {
public $y = 1;
public function test() {
return array(array(array('foobar')));
}
}
function c() {
return array(new foo);
}
var_dump(c()[0]->y); // int(1)
function d() {
$obj = new foo;
return $obj->test();
}
var_dump(d()[0][0][0][3]); // string(1) "b"
function e() {
$y = 'bar';
$x = array('a' => 'foo', 'b' => $y);
return $x;
}
var_dump(e()['b']); // string(3) "bar"
?>
--EXPECTF--
int(5)
Notice: Undefined offset: 0 in %s on line %d
NULL
int(1)
string(1) "b"
string(3) "bar"
|