Browse Source

- Allow write context on array dereferencing from method return

- New tests
experimental/lemon
Felipe Pena 16 years ago
parent
commit
eb0ba9068d
  1. 17
      Zend/tests/dereference_007.phpt
  2. 56
      Zend/tests/dereference_012.phpt
  3. 38
      Zend/tests/dereference_013.phpt
  4. 34
      Zend/tests/dereference_014.phpt
  5. 2
      Zend/zend_language_parser.y

17
Zend/tests/dereference_007.phpt

@ -11,12 +11,27 @@ class foo {
public function b() {
return $this->x;
}
public function c() {
return $x;
}
static public function d() {
}
}
$foo = new foo;
$foo->b()[0] = 1;
$foo->c()[100] = 2;
foo::d()[] = 3;
print "ok\n";
?>
--EXPECTF--
Fatal error: Can't use method return value in write context in %s on line %d
Notice: Undefined variable: x in %s on line %d
ok

56
Zend/tests/dereference_012.phpt

@ -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)
}

38
Zend/tests/dereference_013.phpt

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

34
Zend/tests/dereference_014.phpt

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

2
Zend/zend_language_parser.y

@ -943,7 +943,7 @@ method:
method_or_not:
method { $$ = $1; zend_do_push_object(&$$ TSRMLS_CC); $$.EA = ZEND_PARSED_METHOD_CALL; }
| array_method_dereference { $$ = $1; zend_do_push_object(&$$ TSRMLS_CC); $$.EA = ZEND_PARSED_METHOD_CALL; }
| array_method_dereference { $$ = $1; zend_do_push_object(&$$ TSRMLS_CC); }
| /* empty */ { $$.EA = ZEND_PARSED_MEMBER; }
;

Loading…
Cancel
Save