com php-src: Fix bug #70164 (__COMPILER_HALT_OFFSET __ under namespace is not defined): Zend/te sts/bug70164.phpt Zend/zend_compile.c

From: Date: Wed, 29 Jul 2015 17:18:29 +0000
Subject: com php-src: Fix bug #70164 (__COMPILER_HALT_OFFSET __ under namespace is not defined): Zend/te sts/bug70164.phpt Zend/zend_compile.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-88234@lists.php.net to get a copy of this message
Commit: d45d5271f7802add887b08595eedc41a4012d9e9 Author: Bob Weinand <bobwei9@hotmail.com> Wed, 29 Jul 2015 19:18:13 +0200 Parents: 8f7d816b0d290e3e43b2ba4f3bf265f41af468d0 Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=d45d5271f7802add887b08595eedc41a4012d9e9 Log: Fix bug #70164 (__COMPILER_HALT_OFFSET__ under namespace is not defined) Bugs: https://bugs.php.net/70164 Changed paths: A Zend/tests/bug70164.phpt M Zend/zend_compile.c Diff: diff --git a/Zend/tests/bug70164.phpt b/Zend/tests/bug70164.phpt new file mode 100644 index 0000000..7777be4 --- /dev/null +++ b/Zend/tests/bug70164.phpt @@ -0,0 +1,30 @@ +--TEST-- +__COMPILER_HALT_OFFSET__ is a "magic" constant, which should work if referenced directly, even in a namespace +--FILE-- +<?php + +namespace { + echo __COMPILER_HALT_OFFSET__, "\n"; + echo \__COMPILER_HALT_OFFSET__, "\n"; +} + +namespace Foo { + echo __COMPILER_HALT_OFFSET__, "\n"; + echo \__COMPILER_HALT_OFFSET__, "\n"; + echo namespace\__COMPILER_HALT_OFFSET__, "\n"; + +} + +__halt_compiler(); + +?> +--EXPECTF-- +%d +%d +%d +%d + +Fatal error: Uncaught Error: Undefined constant 'Foo\__COMPILER_HALT_OFFSET__' in %s:%d +Stack trace: +#0 {main} + thrown in %s on line %d diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index a60a446..f6d9e52 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -6493,16 +6493,9 @@ void zend_compile_const(znode *result, zend_ast *ast) /* {{{ */ zend_bool is_fully_qualified; zend_string *orig_name = zend_ast_get_str(name_ast); - zend_string *resolved_name = zend_resolve_const_name( - orig_name, name_ast->attr, &is_fully_qualified); + zend_string *resolved_name = zend_resolve_const_name(orig_name, name_ast->attr, &is_fully_qualified); - if (zend_try_ct_eval_const(&result->u.constant, resolved_name, is_fully_qualified)) { - result->op_type = IS_CONST; - zend_string_release(resolved_name); - return; - } - - if (zend_string_equals_literal(resolved_name, "__COMPILER_HALT_OFFSET__")) { + if (zend_string_equals_literal(resolved_name, "__COMPILER_HALT_OFFSET__") || (name_ast->attr != ZEND_NAME_RELATIVE && zend_string_equals_literal(orig_name, "__COMPILER_HALT_OFFSET__"))) { zend_ast *last = CG(ast); while (last->kind == ZEND_AST_STMT_LIST) { @@ -6511,13 +6504,18 @@ void zend_compile_const(znode *result, zend_ast *ast) /* {{{ */ } if (last->kind == ZEND_AST_HALT_COMPILER) { result->op_type = IS_CONST; - ZVAL_LONG(&result->u.constant, - Z_LVAL_P(zend_ast_get_zval(last->child[0]))); + ZVAL_LONG(&result->u.constant, Z_LVAL_P(zend_ast_get_zval(last->child[0]))); zend_string_release(resolved_name); return; } } + if (zend_try_ct_eval_const(&result->u.constant, resolved_name, is_fully_qualified)) { + result->op_type = IS_CONST; + zend_string_release(resolved_name); + return; + } + opline = zend_emit_op_tmp(result, ZEND_FETCH_CONSTANT, NULL, NULL); opline->op2_type = IS_CONST;

« previous php.cvs (#88234) next »