Skip to content

Commit a09da43

Browse files
committed
Merge branch 'PHP-7.4'
2 parents a97645e + d88b212 commit a09da43

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
Cannot declare class, because the name is already in use
3+
--FILE--
4+
<?php
5+
6+
function test() {
7+
class A {}
8+
}
9+
test();
10+
test();
11+
12+
?>
13+
--EXPECTF--
14+
Fatal error: Cannot declare class A, because the name is already in use in %s on line %d

Zend/zend_compile.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,12 +1057,9 @@ ZEND_API int do_bind_class(zval *lcname, zend_string *lc_parent_name) /* {{{ */
10571057
zv = zend_hash_find_ex(EG(class_table), Z_STR_P(rtd_key), 1);
10581058

10591059
if (UNEXPECTED(!zv)) {
1060-
/* If we're in compile time, in practice, it's quite possible
1061-
* that we'll never reach this class declaration at runtime,
1062-
* so we shut up about it. This allows the if (!defined('FOO')) { return; }
1063-
* approach to work.
1064-
*/
1065-
zend_error_noreturn(E_COMPILE_ERROR, "Cannot declare %s, because the name is already in use", Z_STRVAL_P(lcname));
1060+
ce = zend_hash_find_ptr(EG(class_table), Z_STR_P(lcname));
1061+
ZEND_ASSERT(ce && "Class with lcname should be registered");
1062+
zend_error_noreturn(E_COMPILE_ERROR, "Cannot declare %s %s, because the name is already in use", zend_get_object_type(ce), ZSTR_VAL(ce->name));
10661063
return FAILURE;
10671064
}
10681065

0 commit comments

Comments
 (0)