Skip to content

Commit 18e0d65

Browse files
committed
Treat magic constants like normal constants
1 parent 4c35788 commit 18e0d65

File tree

2 files changed

+33
-9
lines changed

2 files changed

+33
-9
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
Dereferencing of magic constants
3+
--FILE--
4+
<?php
5+
6+
function test() {
7+
var_dump(__FUNCTION__[0]);
8+
var_dump(__FUNCTION__->prop);
9+
try {
10+
__FUNCTION__->method();
11+
} catch (Error $e) {
12+
echo $e->getMessage(), "\n";
13+
}
14+
}
15+
16+
test();
17+
18+
?>
19+
--EXPECTF--
20+
string(1) "t"
21+
22+
Warning: Trying to get property 'prop' of non-object in %s on line %d
23+
NULL
24+
Call to a member function method() on string

Zend/zend_language_parser.y

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,14 +1109,6 @@ dereferencable_scalar:
11091109
scalar:
11101110
T_LNUMBER { $$ = $1; }
11111111
| T_DNUMBER { $$ = $1; }
1112-
| T_LINE { $$ = zend_ast_create_ex(ZEND_AST_MAGIC_CONST, T_LINE); }
1113-
| T_FILE { $$ = zend_ast_create_ex(ZEND_AST_MAGIC_CONST, T_FILE); }
1114-
| T_DIR { $$ = zend_ast_create_ex(ZEND_AST_MAGIC_CONST, T_DIR); }
1115-
| T_TRAIT_C { $$ = zend_ast_create_ex(ZEND_AST_MAGIC_CONST, T_TRAIT_C); }
1116-
| T_METHOD_C { $$ = zend_ast_create_ex(ZEND_AST_MAGIC_CONST, T_METHOD_C); }
1117-
| T_FUNC_C { $$ = zend_ast_create_ex(ZEND_AST_MAGIC_CONST, T_FUNC_C); }
1118-
| T_NS_C { $$ = zend_ast_create_ex(ZEND_AST_MAGIC_CONST, T_NS_C); }
1119-
| T_CLASS_C { $$ = zend_ast_create_ex(ZEND_AST_MAGIC_CONST, T_CLASS_C); }
11201112
| T_START_HEREDOC T_ENCAPSED_AND_WHITESPACE T_END_HEREDOC { $$ = $2; }
11211113
| T_START_HEREDOC T_END_HEREDOC
11221114
{ $$ = zend_ast_create_zval_from_str(ZSTR_EMPTY_ALLOC()); }
@@ -1127,7 +1119,15 @@ scalar:
11271119
;
11281120

11291121
constant:
1130-
name { $$ = zend_ast_create(ZEND_AST_CONST, $1); }
1122+
name { $$ = zend_ast_create(ZEND_AST_CONST, $1); }
1123+
| T_LINE { $$ = zend_ast_create_ex(ZEND_AST_MAGIC_CONST, T_LINE); }
1124+
| T_FILE { $$ = zend_ast_create_ex(ZEND_AST_MAGIC_CONST, T_FILE); }
1125+
| T_DIR { $$ = zend_ast_create_ex(ZEND_AST_MAGIC_CONST, T_DIR); }
1126+
| T_TRAIT_C { $$ = zend_ast_create_ex(ZEND_AST_MAGIC_CONST, T_TRAIT_C); }
1127+
| T_METHOD_C { $$ = zend_ast_create_ex(ZEND_AST_MAGIC_CONST, T_METHOD_C); }
1128+
| T_FUNC_C { $$ = zend_ast_create_ex(ZEND_AST_MAGIC_CONST, T_FUNC_C); }
1129+
| T_NS_C { $$ = zend_ast_create_ex(ZEND_AST_MAGIC_CONST, T_NS_C); }
1130+
| T_CLASS_C { $$ = zend_ast_create_ex(ZEND_AST_MAGIC_CONST, T_CLASS_C); }
11311131
;
11321132

11331133
class_constant:

0 commit comments

Comments
 (0)