]> granicus.if.org Git - php/commitdiff
Treat magic constants like normal constants
authorNikita Popov <nikita.ppv@gmail.com>
Mon, 6 Jan 2020 15:13:39 +0000 (16:13 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Tue, 11 Feb 2020 11:33:23 +0000 (12:33 +0100)
Zend/tests/varSyntax/magic_const_deref.phpt [new file with mode: 0644]
Zend/zend_language_parser.y

diff --git a/Zend/tests/varSyntax/magic_const_deref.phpt b/Zend/tests/varSyntax/magic_const_deref.phpt
new file mode 100644 (file)
index 0000000..28ca4b7
--- /dev/null
@@ -0,0 +1,24 @@
+--TEST--
+Dereferencing of magic constants
+--FILE--
+<?php
+
+function test() {
+    var_dump(__FUNCTION__[0]);
+    var_dump(__FUNCTION__->prop);
+    try {
+        __FUNCTION__->method();
+    } catch (Error $e) {
+        echo $e->getMessage(), "\n";
+    }
+}
+
+test();
+
+?>
+--EXPECTF--
+string(1) "t"
+
+Warning: Trying to get property 'prop' of non-object in %s on line %d
+NULL
+Call to a member function method() on string
index 8db53e11d02ae075fafb064f5f3ca5eb4abc9868..af8b67af5c2b3bdde7afc50ba89cb4cef8a2c8b4 100644 (file)
@@ -1109,14 +1109,6 @@ dereferencable_scalar:
 scalar:
                T_LNUMBER       { $$ = $1; }
        |       T_DNUMBER       { $$ = $1; }
-       |       T_LINE          { $$ = zend_ast_create_ex(ZEND_AST_MAGIC_CONST, T_LINE); }
-       |       T_FILE          { $$ = zend_ast_create_ex(ZEND_AST_MAGIC_CONST, T_FILE); }
-       |       T_DIR           { $$ = zend_ast_create_ex(ZEND_AST_MAGIC_CONST, T_DIR); }
-       |       T_TRAIT_C       { $$ = zend_ast_create_ex(ZEND_AST_MAGIC_CONST, T_TRAIT_C); }
-       |       T_METHOD_C      { $$ = zend_ast_create_ex(ZEND_AST_MAGIC_CONST, T_METHOD_C); }
-       |       T_FUNC_C        { $$ = zend_ast_create_ex(ZEND_AST_MAGIC_CONST, T_FUNC_C); }
-       |       T_NS_C          { $$ = zend_ast_create_ex(ZEND_AST_MAGIC_CONST, T_NS_C); }
-       |       T_CLASS_C       { $$ = zend_ast_create_ex(ZEND_AST_MAGIC_CONST, T_CLASS_C); }
        |       T_START_HEREDOC T_ENCAPSED_AND_WHITESPACE T_END_HEREDOC { $$ = $2; }
        |       T_START_HEREDOC T_END_HEREDOC
                        { $$ = zend_ast_create_zval_from_str(ZSTR_EMPTY_ALLOC()); }
@@ -1127,7 +1119,15 @@ scalar:
 ;
 
 constant:
-               name { $$ = zend_ast_create(ZEND_AST_CONST, $1); }
+               name            { $$ = zend_ast_create(ZEND_AST_CONST, $1); }
+       |       T_LINE          { $$ = zend_ast_create_ex(ZEND_AST_MAGIC_CONST, T_LINE); }
+       |       T_FILE          { $$ = zend_ast_create_ex(ZEND_AST_MAGIC_CONST, T_FILE); }
+       |       T_DIR           { $$ = zend_ast_create_ex(ZEND_AST_MAGIC_CONST, T_DIR); }
+       |       T_TRAIT_C       { $$ = zend_ast_create_ex(ZEND_AST_MAGIC_CONST, T_TRAIT_C); }
+       |       T_METHOD_C      { $$ = zend_ast_create_ex(ZEND_AST_MAGIC_CONST, T_METHOD_C); }
+       |       T_FUNC_C        { $$ = zend_ast_create_ex(ZEND_AST_MAGIC_CONST, T_FUNC_C); }
+       |       T_NS_C          { $$ = zend_ast_create_ex(ZEND_AST_MAGIC_CONST, T_NS_C); }
+       |       T_CLASS_C       { $$ = zend_ast_create_ex(ZEND_AST_MAGIC_CONST, T_CLASS_C); }
 ;
 
 class_constant: