]> granicus.if.org Git - php/commitdiff
Accept static member fetch in new variable (BC)
authorNikita Popov <nikic@php.net>
Fri, 6 Jun 2014 15:05:14 +0000 (17:05 +0200)
committerNikita Popov <nikic@php.net>
Fri, 6 Jun 2014 15:05:14 +0000 (17:05 +0200)
Zend/tests/varSyntax/globalNonSimpleVariableError.phpt [new file with mode: 0644]
Zend/tests/varSyntax/newVariable.phpt [new file with mode: 0644]
Zend/zend_language_parser.y

diff --git a/Zend/tests/varSyntax/globalNonSimpleVariableError.phpt b/Zend/tests/varSyntax/globalNonSimpleVariableError.phpt
new file mode 100644 (file)
index 0000000..ed04921
--- /dev/null
@@ -0,0 +1,10 @@
+--TEST--
+Global keyword only accepts simple variables
+--FILE--
+<?php
+
+global $$foo->bar;
+
+?>
+--EXPECTF--
+Parse error: syntax error, unexpected '->' (T_OBJECT_OPERATOR), expecting ',' or ';' in %s on line %d
diff --git a/Zend/tests/varSyntax/newVariable.phpt b/Zend/tests/varSyntax/newVariable.phpt
new file mode 100644 (file)
index 0000000..360f99a
--- /dev/null
@@ -0,0 +1,39 @@
+--TEST--
+Variable as class name for new expression
+--FILE--
+<?php
+
+$className = 'stdClass';
+$array = ['className' => 'stdClass'];
+$obj = (object) ['className' => 'stdClass'];
+
+class Test {
+    public static $className = 'stdClass';
+}
+$test = 'Test';
+$weird = [0 => (object) ['foo' => 'Test']];
+
+var_dump(new $className);
+var_dump(new $array['className']);
+var_dump(new $array{'className'});
+var_dump(new $obj->className);
+var_dump(new Test::$className);
+var_dump(new $test::$className);
+var_dump(new $weird[0]->foo::$className);
+
+?>
+--EXPECTF--
+object(stdClass)#%d (0) {
+}
+object(stdClass)#%d (0) {
+}
+object(stdClass)#%d (0) {
+}
+object(stdClass)#%d (0) {
+}
+object(stdClass)#%d (0) {
+}
+object(stdClass)#%d (0) {
+}
+object(stdClass)#%d (0) {
+}
index e28949d71cdcd74d5bd0914369ac89d60b79d1dc..013e3ddbf0b641824fd0efd0260125d187dc9715 100644 (file)
@@ -883,13 +883,8 @@ fully_qualified_class_name:
 
 
 class_name_reference:
-               class_name                                              { zend_do_fetch_class(&$$, &$1 TSRMLS_CC); }
-       |       dynamic_class_name_reference    { zend_do_end_variable_parse(&$1, BP_VAR_R, 0 TSRMLS_CC); zend_do_fetch_class(&$$, &$1 TSRMLS_CC); }
-;
-
-
-dynamic_class_name_reference:
-               new_variable { $$ = $1; }
+               class_name              { zend_do_fetch_class(&$$, &$1 TSRMLS_CC); }
+       |       new_variable    { zend_do_end_variable_parse(&$1, BP_VAR_R, 0 TSRMLS_CC); zend_do_fetch_class(&$$, &$1 TSRMLS_CC); }
 ;
 
 exit_expr:
@@ -1115,6 +1110,11 @@ new_variable:
        |       new_variable '{' expr '}' { fetch_string_offset(&$$, &$1, &$3 TSRMLS_CC); }
        |       new_variable T_OBJECT_OPERATOR member_name
                        { zend_do_fetch_property(&$$, &$1, &$3 TSRMLS_CC); }
+       |       class_name T_PAAMAYIM_NEKUDOTAYIM simple_variable
+                       { zend_do_fetch_static_member(&$$, &$1, &$3 TSRMLS_CC); }
+       |       new_variable T_PAAMAYIM_NEKUDOTAYIM simple_variable
+                       { zend_do_end_variable_parse(&$1, BP_VAR_R, 0 TSRMLS_CC);
+                         zend_do_fetch_static_member(&$$, &$1, &$3 TSRMLS_CC); }
 ;
 
 dim_offset: