From: Nikita Popov Date: Wed, 8 Jan 2020 13:18:14 +0000 (+0100) Subject: Fix #65274: Add class name to undef class constant error X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ae5d7604f699dac4fd824e594c7df5439a36c29b;p=php Fix #65274: Add class name to undef class constant error --- diff --git a/NEWS b/NEWS index 9ab884ee43..f1909fda44 100644 --- a/NEWS +++ b/NEWS @@ -6,6 +6,8 @@ PHP NEWS . Removed the pdo_odbc.db2_instance_name php.ini directive. (Kalle) . Fixed bug #77619 (Wrong reflection on MultipleIterator::__construct). (Fabien Villepinte) + . Fixed bug #65274 (Enhance undefined class constant error with class name). + (Nikita) - Date: . Fixed bug #65547 (Default value for sunrise/sunset zenith still wrong). diff --git a/Zend/tests/class_constants_001.phpt b/Zend/tests/class_constants_001.phpt index f36b1af9f6..484157fe4b 100644 --- a/Zend/tests/class_constants_001.phpt +++ b/Zend/tests/class_constants_001.phpt @@ -19,7 +19,7 @@ echo "Done\n"; string(6) "string" int(1) -Fatal error: Uncaught Error: Undefined class constant 'val3' in %s:%d +Fatal error: Uncaught Error: Undefined class constant 'test::val3' in %s:%d Stack trace: #0 {main} thrown in %s on line %d diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index c38499d972..608d24f508 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -5485,7 +5485,8 @@ ZEND_VM_HANDLER(181, ZEND_FETCH_CLASS_CONSTANT, VAR|CONST|UNUSED|CLASS_FETCH, CO } CACHE_POLYMORPHIC_PTR(opline->extended_value, ce, value); } else { - zend_throw_error(NULL, "Undefined class constant '%s'", Z_STRVAL_P(RT_CONSTANT(opline, opline->op2))); + zend_throw_error(NULL, "Undefined class constant '%s::%s'", + ZSTR_VAL(ce->name), Z_STRVAL_P(RT_CONSTANT(opline, opline->op2))); ZVAL_UNDEF(EX_VAR(opline->result.var)); HANDLE_EXCEPTION(); } diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index c5a429a9e3..3940598619 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -5957,7 +5957,8 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FETCH_CLASS_CONSTANT_SPEC_CONS } CACHE_POLYMORPHIC_PTR(opline->extended_value, ce, value); } else { - zend_throw_error(NULL, "Undefined class constant '%s'", Z_STRVAL_P(RT_CONSTANT(opline, opline->op2))); + zend_throw_error(NULL, "Undefined class constant '%s::%s'", + ZSTR_VAL(ce->name), Z_STRVAL_P(RT_CONSTANT(opline, opline->op2))); ZVAL_UNDEF(EX_VAR(opline->result.var)); HANDLE_EXCEPTION(); } @@ -22760,7 +22761,8 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FETCH_CLASS_CONSTANT_SPEC_VAR_ } CACHE_POLYMORPHIC_PTR(opline->extended_value, ce, value); } else { - zend_throw_error(NULL, "Undefined class constant '%s'", Z_STRVAL_P(RT_CONSTANT(opline, opline->op2))); + zend_throw_error(NULL, "Undefined class constant '%s::%s'", + ZSTR_VAL(ce->name), Z_STRVAL_P(RT_CONSTANT(opline, opline->op2))); ZVAL_UNDEF(EX_VAR(opline->result.var)); HANDLE_EXCEPTION(); } @@ -30698,7 +30700,8 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FETCH_CLASS_CONSTANT_SPEC_UNUS } CACHE_POLYMORPHIC_PTR(opline->extended_value, ce, value); } else { - zend_throw_error(NULL, "Undefined class constant '%s'", Z_STRVAL_P(RT_CONSTANT(opline, opline->op2))); + zend_throw_error(NULL, "Undefined class constant '%s::%s'", + ZSTR_VAL(ce->name), Z_STRVAL_P(RT_CONSTANT(opline, opline->op2))); ZVAL_UNDEF(EX_VAR(opline->result.var)); HANDLE_EXCEPTION(); } diff --git a/tests/classes/constants_basic_001.phpt b/tests/classes/constants_basic_001.phpt index af9915c277..796c8d559e 100644 --- a/tests/classes/constants_basic_001.phpt +++ b/tests/classes/constants_basic_001.phpt @@ -79,7 +79,7 @@ string(6) "hello2" Expecting fatal error: -Fatal error: Uncaught Error: Undefined class constant 'c19' in %s:%d +Fatal error: Uncaught Error: Undefined class constant 'C::c19' in %s:%d Stack trace: #0 {main} thrown in %s on line %d diff --git a/tests/classes/constants_visibility_004.phpt b/tests/classes/constants_visibility_004.phpt index 93acacf3c9..983b2e247b 100644 --- a/tests/classes/constants_visibility_004.phpt +++ b/tests/classes/constants_visibility_004.phpt @@ -21,7 +21,7 @@ B::checkConstants(); int(1) int(2) -Fatal error: Uncaught Error: Undefined class constant 'Z' in %s:11 +Fatal error: Uncaught Error: Undefined class constant 'B::Z' in %s:11 Stack trace: #0 %s(15): B::checkConstants() #1 {main}