Browse Source
- Allow write context on array dereferencing from method return
- Allow write context on array dereferencing from method return
- New testsexperimental/lemon
5 changed files with 145 additions and 2 deletions
-
17Zend/tests/dereference_007.phpt
-
56Zend/tests/dereference_012.phpt
-
38Zend/tests/dereference_013.phpt
-
34Zend/tests/dereference_014.phpt
-
2Zend/zend_language_parser.y
@ -0,0 +1,56 @@ |
|||
--TEST-- |
|||
Testing array dereferencing on return of a method with and without reference |
|||
--FILE-- |
|||
<?php |
|||
|
|||
class foo { |
|||
static $x = array(); |
|||
|
|||
public function &a() { |
|||
self::$x = array(1, 2, 3); |
|||
return self::$x; |
|||
} |
|||
|
|||
public function b() { |
|||
$x = array(1); |
|||
$x[] = 2; |
|||
return $x; |
|||
} |
|||
} |
|||
|
|||
$foo = new foo; |
|||
|
|||
// Changing the static variable |
|||
$foo->a()[0] = 2; |
|||
var_dump($foo::$x); |
|||
|
|||
$foo->b()[] = new stdClass; |
|||
|
|||
$h = $foo->b(); |
|||
var_dump($h); |
|||
|
|||
$h[0] = 3; |
|||
var_dump($h); |
|||
|
|||
?> |
|||
--EXPECT-- |
|||
array(3) { |
|||
[0]=> |
|||
int(2) |
|||
[1]=> |
|||
int(2) |
|||
[2]=> |
|||
int(3) |
|||
} |
|||
array(2) { |
|||
[0]=> |
|||
int(1) |
|||
[1]=> |
|||
int(2) |
|||
} |
|||
array(2) { |
|||
[0]=> |
|||
int(3) |
|||
[1]=> |
|||
int(2) |
|||
} |
|||
@ -0,0 +1,38 @@ |
|||
--TEST-- |
|||
Testing array dereferencing on array returned from __call method |
|||
--FILE-- |
|||
<?php |
|||
|
|||
error_reporting(E_ALL); |
|||
|
|||
class foo { |
|||
public $x = array(2); |
|||
|
|||
public function __call($x, $y) { |
|||
if (count($this->x) == 1) { |
|||
$this->x[] = $y[0]; |
|||
} |
|||
return $this->x; |
|||
} |
|||
} |
|||
|
|||
$foo = new foo; |
|||
|
|||
$x = array(1); |
|||
|
|||
$foo->b($x)[1] = 3; |
|||
|
|||
var_dump($foo->b()[0]); |
|||
var_dump($foo->b()[1]); |
|||
var_dump($foo->b()[2]); |
|||
|
|||
?> |
|||
--EXPECTF-- |
|||
int(2) |
|||
array(1) { |
|||
[0]=> |
|||
int(1) |
|||
} |
|||
|
|||
Notice: Undefined offset: %d in %s on line %d |
|||
NULL |
|||
@ -0,0 +1,34 @@ |
|||
--TEST-- |
|||
Trying to create an object from dereferencing uninitialized variable |
|||
--FILE-- |
|||
<?php |
|||
|
|||
error_reporting(E_ALL); |
|||
|
|||
class foo { |
|||
public $x; |
|||
static public $y; |
|||
|
|||
public function a() { |
|||
return $this->x; |
|||
} |
|||
|
|||
static public function b() { |
|||
return self::$y; |
|||
} |
|||
} |
|||
|
|||
$foo = new foo; |
|||
$h = $foo->a()[0]->a; |
|||
var_dump($h); |
|||
|
|||
$h = foo::b()[1]->b; |
|||
var_dump($h); |
|||
|
|||
?> |
|||
--EXPECTF-- |
|||
Notice: Trying to get property of non-object in %s on line %d |
|||
NULL |
|||
|
|||
Notice: Trying to get property of non-object in %s on line %d |
|||
NULL |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue