felipe Sat, 12 Jun 2010 16:11:10 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=300409
Log:
- Allow write context on array dereferencing from method return
- New tests
Changed paths:
U php/php-src/trunk/Zend/tests/dereference_007.phpt
A php/php-src/trunk/Zend/tests/dereference_012.phpt
A php/php-src/trunk/Zend/tests/dereference_013.phpt
A php/php-src/trunk/Zend/tests/dereference_014.phpt
U php/php-src/trunk/Zend/zend_language_parser.y
Modified: php/php-src/trunk/Zend/tests/dereference_007.phpt
===================================================================
--- php/php-src/trunk/Zend/tests/dereference_007.phpt 2010-06-12 16:07:20 UTC
(rev 300408)
+++ php/php-src/trunk/Zend/tests/dereference_007.phpt 2010-06-12 16:11:10 UTC
(rev 300409)
@@ -11,12 +11,27 @@
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
Added: php/php-src/trunk/Zend/tests/dereference_012.phpt
===================================================================
--- php/php-src/trunk/Zend/tests/dereference_012.phpt
(rev 0)
+++ php/php-src/trunk/Zend/tests/dereference_012.phpt 2010-06-12 16:11:10 UTC
(rev 300409)
@@ -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)
+}
Property changes on: php/php-src/trunk/Zend/tests/dereference_012.phpt
___________________________________________________________________
Added: svn:keywords
+ Id Rev Revision
Added: svn:eol-style
+ native
Added: php/php-src/trunk/Zend/tests/dereference_013.phpt
===================================================================
--- php/php-src/trunk/Zend/tests/dereference_013.phpt
(rev 0)
+++ php/php-src/trunk/Zend/tests/dereference_013.phpt 2010-06-12 16:11:10 UTC
(rev 300409)
@@ -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
Property changes on: php/php-src/trunk/Zend/tests/dereference_013.phpt
___________________________________________________________________
Added: svn:keywords
+ Id Rev Revision
Added: svn:eol-style
+ native
Added: php/php-src/trunk/Zend/tests/dereference_014.phpt
===================================================================
--- php/php-src/trunk/Zend/tests/dereference_014.phpt
(rev 0)
+++ php/php-src/trunk/Zend/tests/dereference_014.phpt 2010-06-12 16:11:10 UTC
(rev 300409)
@@ -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
Property changes on: php/php-src/trunk/Zend/tests/dereference_014.phpt
___________________________________________________________________
Added: svn:keywords
+ Id Rev Revision
Added: svn:eol-style
+ native
Modified: php/php-src/trunk/Zend/zend_language_parser.y
===================================================================
--- php/php-src/trunk/Zend/zend_language_parser.y 2010-06-12 16:07:20 UTC
(rev 300408)
+++ php/php-src/trunk/Zend/zend_language_parser.y 2010-06-12 16:11:10 UTC
(rev 300409)
@@ -943,7 +943,7 @@
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; }
;
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php