diff options
Diffstat (limited to 'Zend')
| -rw-r--r-- | Zend/tests/bug37811.phpt | 7 | ||||
| -rw-r--r-- | Zend/tests/bug43344_1.phpt | 43 | ||||
| -rw-r--r-- | Zend/tests/bug47572.phpt | 5 | ||||
| -rw-r--r-- | Zend/tests/bug69755.phpt | 5 | ||||
| -rw-r--r-- | Zend/tests/bug69788.phpt | 5 | ||||
| -rw-r--r-- | Zend/tests/bug72944.phpt | 5 | ||||
| -rw-r--r-- | Zend/tests/bug73163.phpt | 22 | ||||
| -rw-r--r-- | Zend/tests/constants_002.phpt | 12 | ||||
| -rw-r--r-- | Zend/tests/constants_005.phpt | 7 | ||||
| -rw-r--r-- | Zend/tests/ns_041.phpt | 6 | ||||
| -rw-r--r-- | Zend/tests/ns_076.phpt | 38 | ||||
| -rw-r--r-- | Zend/zend_compile.c | 17 | ||||
| -rw-r--r-- | Zend/zend_compile.h | 3 | ||||
| -rw-r--r-- | Zend/zend_constants.c | 2 | ||||
| -rw-r--r-- | Zend/zend_execute.c | 20 | ||||
| -rw-r--r-- | Zend/zend_execute_API.c | 21 |
16 files changed, 92 insertions, 126 deletions
diff --git a/Zend/tests/bug37811.phpt b/Zend/tests/bug37811.phpt index 96645d0354..8321459d5d 100644 --- a/Zend/tests/bug37811.phpt +++ b/Zend/tests/bug37811.phpt @@ -23,6 +23,7 @@ string(3) "Foo" Warning: Constants may only evaluate to scalar values, arrays or resources in %sbug37811.php on line %d -Warning: Use of undefined constant Baz - assumed 'Baz' (this will throw an Error in a future version of PHP) in %sbug37811.php on line %d -string(3) "Baz" -===DONE=== +Fatal error: Uncaught Error: Undefined constant 'Baz' in %s:%d +Stack trace: +#0 {main} + thrown in %s on line %d diff --git a/Zend/tests/bug43344_1.phpt b/Zend/tests/bug43344_1.phpt index 4635240699..28af70dc67 100644 --- a/Zend/tests/bug43344_1.phpt +++ b/Zend/tests/bug43344_1.phpt @@ -3,6 +3,8 @@ Bug #43344.1 (Wrong error message for undefined namespace constant) --FILE-- <?php namespace Foo; +use Error; + function f1($a=bar) { return $a; } @@ -13,20 +15,31 @@ function f3($a=array(bar=>0)) { reset($a); return key($a); } -echo bar."\n"; -echo f1()."\n"; -echo f2()."\n"; -echo f3()."\n"; -?> ---EXPECTF-- -Warning: Use of undefined constant bar - assumed 'bar' (this will throw an Error in a future version of PHP) in %sbug43344_1.php on line 13 -bar -Warning: Use of undefined constant bar - assumed 'bar' (this will throw an Error in a future version of PHP) in %sbug43344_1.php on line 3 -bar - -Warning: Use of undefined constant bar - assumed 'bar' (this will throw an Error in a future version of PHP) in %sbug43344_1.php on line 6 -bar +try { + echo bar."\n"; +} catch (Error $e) { + echo $e->getMessage(), "\n"; +} +try { + echo f1()."\n"; +} catch (Error $e) { + echo $e->getMessage(), "\n"; +} +try { + echo f2()."\n"; +} catch (Error $e) { + echo $e->getMessage(), "\n"; +} +try { + echo f3()."\n"; +} catch (Error $e) { + echo $e->getMessage(), "\n"; +} -Warning: Use of undefined constant bar - assumed 'bar' (this will throw an Error in a future version of PHP) in %sbug43344_1.php on line 9 -bar +?> +--EXPECT-- +Undefined constant 'Foo\bar' +Undefined constant 'Foo\bar' +Undefined constant 'Foo\bar' +Undefined constant 'Foo\bar' diff --git a/Zend/tests/bug47572.phpt b/Zend/tests/bug47572.phpt index 67bb3ec111..7a44cc6e7f 100644 --- a/Zend/tests/bug47572.phpt +++ b/Zend/tests/bug47572.phpt @@ -14,4 +14,7 @@ $foo = new Foo(); ?> --EXPECTF-- -Warning: Use of undefined constant FOO - assumed 'FOO' (this will throw an Error in a future version of PHP) in %s on line %d +Fatal error: Uncaught Error: Undefined constant 'FOO' in %s:%d +Stack trace: +#0 {main} + thrown in %s on line %d diff --git a/Zend/tests/bug69755.phpt b/Zend/tests/bug69755.phpt index 08432808e2..e419756d26 100644 --- a/Zend/tests/bug69755.phpt +++ b/Zend/tests/bug69755.phpt @@ -5,4 +5,7 @@ Bug #69755: segfault in ZEND_CONCAT_SPEC_TMPVAR_CONST_HANDLER c . 10; ?> --EXPECTF-- -Warning: Use of undefined constant c - assumed 'c' (this will throw an Error in a future version of PHP) in %sbug69755.php on line 2 +Fatal error: Uncaught Error: Undefined constant 'c' in %s:%d +Stack trace: +#0 {main} + thrown in %s on line %d diff --git a/Zend/tests/bug69788.phpt b/Zend/tests/bug69788.phpt index 326328ccfa..6e877f78fa 100644 --- a/Zend/tests/bug69788.phpt +++ b/Zend/tests/bug69788.phpt @@ -5,4 +5,7 @@ Bug #69788: Malformed script causes Uncaught Error in php-cgi, valgrind SIGILL --EXPECTF-- Notice: Array to string conversion in %s on line %d -Warning: Use of undefined constant t - assumed 't' (this will throw an Error in a future version of PHP) in %s on line %d +Fatal error: Uncaught Error: Undefined constant 't' in %s:%d +Stack trace: +#0 {main} + thrown in %s on line %d diff --git a/Zend/tests/bug72944.phpt b/Zend/tests/bug72944.phpt index 5f494beb40..75a4edb565 100644 --- a/Zend/tests/bug72944.phpt +++ b/Zend/tests/bug72944.phpt @@ -2,11 +2,10 @@ Bug #72944 (Null pointer deref in zval_delref_p). --FILE-- <?php +define('e', 'e'); "a"== e & $A = $A? 0 : 0 ?:0; echo "OK\n"; ?> --EXPECTF-- -Warning: Use of undefined constant e - assumed 'e' (this will throw an Error in a future version of PHP) in %sbug72944.php on line 2 - -Notice: Undefined variable: A in %sbug72944.php on line 2 +Notice: Undefined variable: A in %sbug72944.php on line 3 OK diff --git a/Zend/tests/bug73163.phpt b/Zend/tests/bug73163.phpt deleted file mode 100644 index 5c0560458d..0000000000 --- a/Zend/tests/bug73163.phpt +++ /dev/null @@ -1,22 +0,0 @@ ---TEST-- -Bug #73163 (PHP hangs if error handler throws while accessing undef const in default value) ---FILE-- -<?php - -function doSomething(string $value = UNDEFINED) { -} - -set_error_handler(function($errno, $errstr) { - throw new Exception($errstr); -}); - -doSomething(); - -?> ---EXPECTF-- -Fatal error: Uncaught Exception: Use of undefined constant UNDEFINED - assumed 'UNDEFINED' (this will throw an Error in a future version of PHP) in %s:%d -Stack trace: -#0 %s(%d): {closure}(%s) -#1 %s(%d): doSomething() -#2 {main} - thrown in %s on line %d diff --git a/Zend/tests/constants_002.phpt b/Zend/tests/constants_002.phpt index b0cf1db61f..ddb2e67307 100644 --- a/Zend/tests/constants_002.phpt +++ b/Zend/tests/constants_002.phpt @@ -4,7 +4,11 @@ Defining constants with non-scalar values <?php define('foo', new stdClass); -var_dump(foo); +try { + var_dump(foo); +} catch (Error $e) { + echo $e->getMessage(), "\n"; +} define('foo', fopen(__FILE__, 'r')); var_dump(foo); @@ -12,7 +16,5 @@ var_dump(foo); ?> --EXPECTF-- Warning: Constants may only evaluate to scalar values, arrays or resources in %s on line %d - -Warning: Use of undefined constant foo - assumed 'foo' (this will throw an Error in a future version of PHP) in %s on line %d -string(%d) "foo" -resource(%d) of type (stream) +Undefined constant 'foo' +resource(5) of type (stream) diff --git a/Zend/tests/constants_005.phpt b/Zend/tests/constants_005.phpt index b5a3a6bd38..27ab0259d1 100644 --- a/Zend/tests/constants_005.phpt +++ b/Zend/tests/constants_005.phpt @@ -2,11 +2,10 @@ Persistent case insensitive and user defined constants --FILE-- <?php -var_dump(ZEND_THREAD_safe); +var_dump(defined('ZEND_THREAD_safe')); define("ZEND_THREAD_safe", 123); var_dump(ZEND_THREAD_safe); ?> ---EXPECTF-- -Warning: Use of undefined constant ZEND_THREAD_safe - assumed 'ZEND_THREAD_safe' (this will throw an Error in a future version of PHP) in %s on line %d -string(16) "ZEND_THREAD_safe" +--EXPECT-- +bool(false) int(123) diff --git a/Zend/tests/ns_041.phpt b/Zend/tests/ns_041.phpt index bd9dfbd093..3a2fe7758b 100644 --- a/Zend/tests/ns_041.phpt +++ b/Zend/tests/ns_041.phpt @@ -17,5 +17,7 @@ ok ok ok -Warning: Use of undefined constant BAR - assumed 'BAR' (this will throw an Error in a future version of PHP) in %sns_041.php on line 9 -BAR +Fatal error: Uncaught Error: Undefined constant 'test\ns1\BAR' in %s:%d +Stack trace: +#0 {main} + thrown in %s on line %d diff --git a/Zend/tests/ns_076.phpt b/Zend/tests/ns_076.phpt index ea97e924b1..0db8aeba62 100644 --- a/Zend/tests/ns_076.phpt +++ b/Zend/tests/ns_076.phpt @@ -3,26 +3,28 @@ --FILE-- <?php namespace foo; +use Error; -$a = array(unknown => unknown); - -echo unknown; -echo "\n"; -var_dump($a); -echo \unknown; ---EXPECTF-- -Warning: Use of undefined constant unknown - assumed 'unknown' (this will throw an Error in a future version of PHP) in %sns_076.php on line %d +try { + $a = array(unknown => unknown); +} catch (Error $e) { + echo $e->getMessage(), "\n"; +} -Warning: Use of undefined constant unknown - assumed 'unknown' (this will throw an Error in a future version of PHP) in %sns_076.php on line %d +try { + echo unknown; +} catch (Error $e) { + echo $e->getMessage(), "\n"; +} -Warning: Use of undefined constant unknown - assumed 'unknown' (this will throw an Error in a future version of PHP) in %sns_076.php on line %d -unknown -array(1) { - ["unknown"]=> - %s(7) "unknown" +try { + echo \unknown; +} catch (Error $e) { + echo $e->getMessage(), "\n"; } -Fatal error: Uncaught Error: Undefined constant 'unknown' in %sns_076.php:%d -Stack trace: -#0 {main} - thrown in %sns_076.php on line %d +?> +--EXPECT-- +Undefined constant 'foo\unknown' +Undefined constant 'foo\unknown' +Undefined constant 'unknown' diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index d153bf79f4..b56356660b 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -7643,19 +7643,13 @@ void zend_compile_const(znode *result, zend_ast *ast) /* {{{ */ opline = zend_emit_op_tmp(result, ZEND_FETCH_CONSTANT, NULL, NULL); opline->op2_type = IS_CONST; - if (is_fully_qualified) { + if (is_fully_qualified || !FC(current_namespace)) { opline->op2.constant = zend_add_const_name_literal( resolved_name, 0); } else { - opline->op1.num = IS_CONSTANT_UNQUALIFIED; - if (FC(current_namespace)) { - opline->op1.num |= IS_CONSTANT_IN_NAMESPACE; - opline->op2.constant = zend_add_const_name_literal( - resolved_name, 1); - } else { - opline->op2.constant = zend_add_const_name_literal( - resolved_name, 0); - } + opline->op1.num = IS_CONSTANT_UNQUALIFIED_IN_NAMESPACE; + opline->op2.constant = zend_add_const_name_literal( + resolved_name, 1); } opline->extended_value = zend_alloc_cache_slot(); } @@ -7985,7 +7979,8 @@ void zend_compile_const_expr_const(zend_ast **ast_ptr) /* {{{ */ } zend_ast_destroy(ast); - *ast_ptr = zend_ast_create_constant(resolved_name, !is_fully_qualified ? IS_CONSTANT_UNQUALIFIED : 0); + *ast_ptr = zend_ast_create_constant(resolved_name, + !is_fully_qualified && FC(current_namespace) ? IS_CONSTANT_UNQUALIFIED_IN_NAMESPACE : 0); } /* }}} */ diff --git a/Zend/zend_compile.h b/Zend/zend_compile.h index 23da64abb7..833139eafc 100644 --- a/Zend/zend_compile.h +++ b/Zend/zend_compile.h @@ -917,9 +917,8 @@ void zend_assert_valid_class_name(const zend_string *const_name); #define ZEND_DIM_IS 1 -#define IS_CONSTANT_UNQUALIFIED 0x010 #define IS_CONSTANT_CLASS 0x080 /* __CLASS__ in trait */ -#define IS_CONSTANT_IN_NAMESPACE 0x100 +#define IS_CONSTANT_UNQUALIFIED_IN_NAMESPACE 0x100 static zend_always_inline int zend_check_arg_send_type(const zend_function *zf, uint32_t arg_num, uint32_t mask) { diff --git a/Zend/zend_constants.c b/Zend/zend_constants.c index 6371492dc0..e38dc61fff 100644 --- a/Zend/zend_constants.c +++ b/Zend/zend_constants.c @@ -424,7 +424,7 @@ failure: return &c->value; } - if (!(flags & IS_CONSTANT_UNQUALIFIED)) { + if (!(flags & IS_CONSTANT_UNQUALIFIED_IN_NAMESPACE)) { return NULL; } diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index 39155e8827..519b295cca 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -4153,7 +4153,7 @@ static zend_always_inline int _zend_quick_get_constant( zv = zend_hash_find_ex(EG(zend_constants), Z_STR_P(key), 1); if (zv) { c = (zend_constant*)Z_PTR_P(zv); - } else if ((flags & (IS_CONSTANT_IN_NAMESPACE|IS_CONSTANT_UNQUALIFIED)) == (IS_CONSTANT_IN_NAMESPACE|IS_CONSTANT_UNQUALIFIED)) { + } else if (flags & IS_CONSTANT_UNQUALIFIED_IN_NAMESPACE) { key++; zv = zend_hash_find_ex(EG(zend_constants), Z_STR_P(key), 1); if (zv) { @@ -4163,22 +4163,8 @@ static zend_always_inline int _zend_quick_get_constant( if (!c) { if (!check_defined_only) { - if ((opline->op1.num & IS_CONSTANT_UNQUALIFIED) != 0) { - char *actual = (char *)zend_memrchr(Z_STRVAL_P(RT_CONSTANT(opline, opline->op2)), '\\', Z_STRLEN_P(RT_CONSTANT(opline, opline->op2))); - if (!actual) { - ZVAL_STR_COPY(EX_VAR(opline->result.var), Z_STR_P(RT_CONSTANT(opline, opline->op2))); - } else { - actual++; - ZVAL_STRINGL(EX_VAR(opline->result.var), - actual, Z_STRLEN_P(RT_CONSTANT(opline, opline->op2)) - (actual - Z_STRVAL_P(RT_CONSTANT(opline, opline->op2)))); - } - /* non-qualified constant - allow text substitution */ - zend_error(E_WARNING, "Use of undefined constant %s - assumed '%s' (this will throw an Error in a future version of PHP)", - Z_STRVAL_P(EX_VAR(opline->result.var)), Z_STRVAL_P(EX_VAR(opline->result.var))); - } else { - zend_throw_error(NULL, "Undefined constant '%s'", Z_STRVAL_P(RT_CONSTANT(opline, opline->op2))); - ZVAL_UNDEF(EX_VAR(opline->result.var)); - } + zend_throw_error(NULL, "Undefined constant '%s'", Z_STRVAL_P(RT_CONSTANT(opline, opline->op2))); + ZVAL_UNDEF(EX_VAR(opline->result.var)); } return FAILURE; } diff --git a/Zend/zend_execute_API.c b/Zend/zend_execute_API.c index 9215717bcc..5ed80be6ff 100644 --- a/Zend/zend_execute_API.c +++ b/Zend/zend_execute_API.c @@ -566,29 +566,10 @@ ZEND_API int zend_use_undefined_constant(zend_string *name, zend_ast_attr attr, } else if ((colon = (char*)zend_memrchr(ZSTR_VAL(name), ':', ZSTR_LEN(name)))) { zend_throw_error(NULL, "Undefined class constant '%s'", ZSTR_VAL(name)); return FAILURE; - } else if ((attr & IS_CONSTANT_UNQUALIFIED) == 0) { + } else { zend_throw_error(NULL, "Undefined constant '%s'", ZSTR_VAL(name)); return FAILURE; - } else { - char *actual = ZSTR_VAL(name); - size_t actual_len = ZSTR_LEN(name); - char *slash = (char *) zend_memrchr(actual, '\\', actual_len); - - if (slash) { - actual = slash + 1; - actual_len -= (actual - ZSTR_VAL(name)); - } - - zend_error(E_WARNING, "Use of undefined constant %s - assumed '%s' (this will throw an Error in a future version of PHP)", actual, actual); - if (EG(exception)) { - return FAILURE; - } else { - zend_string *result_str = zend_string_init(actual, actual_len, 0); - zval_ptr_dtor_nogc(result); - ZVAL_NEW_STR(result, result_str); - } } - return SUCCESS; } /* }}} */ |
