Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Zend/tests/class_alias_002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ class_alias('foo', 'FOO');

?>
--EXPECTF--
Warning: Cannot declare class FOO, because the name is already in use in %s on line %d
Warning: Cannot redeclare class FOO (previously declared in %s:%d) in %s on line %d
2 changes: 1 addition & 1 deletion Zend/tests/class_alias_004.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ class_alias('foo', 'test');

?>
--EXPECTF--
Warning: Cannot declare class test, because the name is already in use in %s on line %d
Warning: Cannot redeclare class test (previously declared in %s:%d) in %s on line %d
2 changes: 1 addition & 1 deletion Zend/tests/class_alias_010.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ class b { }

?>
--EXPECTF--
Warning: Cannot declare interface b, because the name is already in use in %s on line %d
Warning: Cannot redeclare interface b (previously declared in %s:%d) in %s on line %d
2 changes: 1 addition & 1 deletion Zend/tests/class_alias_019.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ class_alias('\foo', 'foo');

?>
--EXPECTF--
Warning: Cannot declare class foo, because the name is already in use in %s on line %d
Warning: Cannot redeclare class foo (previously declared in %s:%d) in %s on line %d
4 changes: 2 additions & 2 deletions Zend/tests/declare_already_in_use.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--TEST--
Cannot declare class, because the name is already in use
Cannot redeclare class
--FILE--
<?php

Expand All @@ -11,4 +11,4 @@ test();

?>
--EXPECTF--
Fatal error: Cannot declare class A, because the name is already in use in %s on line %d
Fatal error: Cannot redeclare class A (previously declared in %s:%d) in %s on line %d
2 changes: 1 addition & 1 deletion Zend/tests/delayed_early_binding_redeclaration.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ include __DIR__ . '/delayed_early_binding_redeclaration-2.inc';
var_dump(class_exists(Bar::class));
?>
--EXPECTF--
Fatal error: Cannot declare class Bar, because the name is already in use in %sdelayed_early_binding_redeclaration-2.inc on line %d
Fatal error: Cannot redeclare class Bar (previously declared in %sdelayed_early_binding_redeclaration-1.inc:2) in %sdelayed_early_binding_redeclaration-2.inc on line %d
2 changes: 1 addition & 1 deletion Zend/tests/errmsg_026.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ class stdclass {
echo "Done\n";
?>
--EXPECTF--
Fatal error: Cannot declare class stdclass, because the name is already in use in %s on line %d
Fatal error: Cannot redeclare class stdClass in %s on line %d
2 changes: 1 addition & 1 deletion Zend/tests/inter_06.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ interface stdClass { }

?>
--EXPECTF--
Fatal error: Cannot declare interface stdClass, because the name is already in use in %s on line %d
Fatal error: Cannot redeclare class stdClass in %s on line %d
2 changes: 1 addition & 1 deletion Zend/tests/name_collision_01.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ class A { }

?>
--EXPECTF--
Fatal error: Cannot declare class A, because the name is already in use in %s on line %d
Fatal error: Cannot redeclare class A (previously declared in %s:%d) in %s on line %d
2 changes: 1 addition & 1 deletion Zend/tests/name_collision_02.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ interface A { }

?>
--EXPECTF--
Fatal error: Cannot declare interface A, because the name is already in use in %s on line %d
Fatal error: Cannot redeclare class A (previously declared in %s:%d) in %s on line %d
2 changes: 1 addition & 1 deletion Zend/tests/name_collision_03.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ trait A { }

?>
--EXPECTF--
Fatal error: Cannot declare trait A, because the name is already in use in %s on line %d
Fatal error: Cannot redeclare class A (previously declared in %s:%d) in %s on line %d
2 changes: 1 addition & 1 deletion Zend/tests/name_collision_04.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ interface A { }

?>
--EXPECTF--
Fatal error: Cannot declare interface A, because the name is already in use in %s on line %d
Fatal error: Cannot redeclare interface A (previously declared in %s:%d) in %s on line %d
2 changes: 1 addition & 1 deletion Zend/tests/name_collision_05.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ trait A { }

?>
--EXPECTF--
Fatal error: Cannot declare trait A, because the name is already in use in %s on line %d
Fatal error: Cannot redeclare interface A (previously declared in %s:%d) in %s on line %d
2 changes: 1 addition & 1 deletion Zend/tests/name_collision_06.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ trait A { }

?>
--EXPECTF--
Fatal error: Cannot declare trait A, because the name is already in use in %s on line %d
Fatal error: Cannot redeclare trait A (previously declared in %s:%d) in %s on line %d
2 changes: 1 addition & 1 deletion Zend/tests/name_collision_07.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ namespace Bazzle {
}
?>
--EXPECTF--
Fatal error: Cannot declare class Bazzle\Bar because the name is already in use in %s on line %d
Fatal error: Cannot redeclare class Bazzle\Bar (previously declared as local import) in %s on line %d
2 changes: 1 addition & 1 deletion Zend/tests/name_collision_08.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ namespace Bazzle {
}
?>
--EXPECTF--
Fatal error: Cannot declare function Bazzle\bar because the name is already in use in %s on line %d
Fatal error: Cannot redeclare Bazzle\bar() (previously declared as local import) in %s on line %d
2 changes: 1 addition & 1 deletion Zend/tests/ns_029.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ class Foo {
new Foo();
?>
--EXPECTF--
Fatal error: Cannot declare class Foo because the name is already in use in %sns_029.php on line 4
Fatal error: Cannot redeclare class Foo (previously declared as local import) in %sns_029.php on line 4
2 changes: 1 addition & 1 deletion Zend/tests/use_function/define_imported.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ namespace {

?>
--EXPECTF--
Fatal error: Cannot declare function bar because the name is already in use in %s on line %d
Fatal error: Cannot redeclare bar() (previously declared as local import) in %s on line %d
20 changes: 20 additions & 0 deletions Zend/zend_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,26 @@ ZEND_API ZEND_COLD void zend_argument_value_error(uint32_t arg_num, const char *
}
/* }}} */

ZEND_API ZEND_COLD void zend_class_redeclaration_error_ex(int type, zend_string *new_name, zend_class_entry *old_ce)
{
if (old_ce->type == ZEND_INTERNAL_CLASS) {
zend_error(type, "Cannot redeclare %s %s",
zend_get_object_type(old_ce),
ZSTR_VAL(new_name));
} else {
zend_error(type, "Cannot redeclare %s %s (previously declared in %s:%d)",
zend_get_object_type(old_ce),
ZSTR_VAL(new_name),
ZSTR_VAL(old_ce->info.user.filename),
old_ce->info.user.line_start);
}
}

ZEND_API ZEND_COLD void zend_class_redeclaration_error(int type, zend_class_entry *old_ce)
{
zend_class_redeclaration_error_ex(type, old_ce->name, old_ce);
}

ZEND_API bool ZEND_FASTCALL zend_parse_arg_class(zval *arg, zend_class_entry **pce, uint32_t num, bool check_null) /* {{{ */
{
zend_class_entry *ce_base = *pce;
Expand Down
2 changes: 2 additions & 0 deletions Zend/zend_API.h
Original file line number Diff line number Diff line change
Expand Up @@ -1563,6 +1563,8 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_argument_error_variadic(zend_class_en
ZEND_API ZEND_COLD void zend_argument_error(zend_class_entry *error_ce, uint32_t arg_num, const char *format, ...);
ZEND_API ZEND_COLD void zend_argument_type_error(uint32_t arg_num, const char *format, ...);
ZEND_API ZEND_COLD void zend_argument_value_error(uint32_t arg_num, const char *format, ...);
ZEND_API ZEND_COLD void zend_class_redeclaration_error(int type, zend_class_entry *old_ce);
ZEND_API ZEND_COLD void zend_class_redeclaration_error_ex(int type, zend_string *new_name, zend_class_entry *old_ce);

#define ZPP_ERROR_OK 0
#define ZPP_ERROR_FAILURE 1
Expand Down
2 changes: 1 addition & 1 deletion Zend/zend_builtin_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -1152,7 +1152,7 @@ ZEND_FUNCTION(class_alias)
if (zend_register_class_alias_ex(ZSTR_VAL(alias_name), ZSTR_LEN(alias_name), ce, false) == SUCCESS) {
RETURN_TRUE;
} else {
zend_error(E_WARNING, "Cannot declare %s %s, because the name is already in use", zend_get_object_type(ce), ZSTR_VAL(alias_name));
zend_class_redeclaration_error_ex(E_WARNING, alias_name, ce);
RETURN_FALSE;
}
} else {
Expand Down
14 changes: 8 additions & 6 deletions Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -1260,7 +1260,9 @@ ZEND_API zend_class_entry *zend_bind_class_in_slot(
success = zend_hash_add_ptr(EG(class_table), Z_STR_P(lcname), ce) != NULL;
}
if (UNEXPECTED(!success)) {
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));
zend_class_entry *old_class = zend_hash_find_ptr(EG(class_table), Z_STR_P(lcname));
ZEND_ASSERT(old_class);
zend_class_redeclaration_error(E_COMPILE_ERROR, old_class);
return NULL;
}

Expand Down Expand Up @@ -1298,7 +1300,7 @@ ZEND_API zend_result do_bind_class(zval *lcname, zend_string *lc_parent_name) /*
if (UNEXPECTED(!zv)) {
ce = zend_hash_find_ptr(EG(class_table), Z_STR_P(lcname));
ZEND_ASSERT(ce);
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));
zend_class_redeclaration_error(E_COMPILE_ERROR, ce);
return FAILURE;
}

Expand Down Expand Up @@ -7752,8 +7754,8 @@ static zend_string *zend_begin_func_decl(znode *result, zend_op_array *op_array,
zend_string *import_name =
zend_hash_find_ptr_lc(FC(imports_function), unqualified_name);
if (import_name && !zend_string_equals_ci(lcname, import_name)) {
zend_error_noreturn(E_COMPILE_ERROR, "Cannot declare function %s "
"because the name is already in use", ZSTR_VAL(name));
zend_error_noreturn(E_COMPILE_ERROR, "Cannot redeclare %s() (previously declared as local import)",
ZSTR_VAL(name));
}
}

Expand Down Expand Up @@ -8318,8 +8320,8 @@ static void zend_compile_class_decl(znode *result, zend_ast *ast, bool toplevel)
zend_string *import_name =
zend_hash_find_ptr_lc(FC(imports), unqualified_name);
if (import_name && !zend_string_equals_ci(lcname, import_name)) {
zend_error_noreturn(E_COMPILE_ERROR, "Cannot declare class %s "
"because the name is already in use", ZSTR_VAL(name));
zend_error_noreturn(E_COMPILE_ERROR, "Cannot redeclare class %s "
"(previously declared as local import)", ZSTR_VAL(name));
}
}

Expand Down
4 changes: 3 additions & 1 deletion Zend/zend_inheritance.c
Original file line number Diff line number Diff line change
Expand Up @@ -3331,7 +3331,9 @@ static zend_always_inline bool register_early_bound_ce(zval *delayed_early_bindi
return true;
}
}
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));
zend_class_entry *old_ce = zend_hash_find_ptr(EG(class_table), lcname);
ZEND_ASSERT(old_ce);
zend_class_redeclaration_error(E_COMPILE_ERROR, old_ce);
return false;
}
if (zend_hash_add_ptr(CG(class_table), lcname, ce) != NULL) {
Expand Down
2 changes: 1 addition & 1 deletion ext/opcache/tests/bug67215.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ unlink($file_c);
unlink($file_p);
?>
--EXPECTF--
Fatal error: Cannot declare class p, because the name is already in use in %sbug67215.p.php on line %d
Fatal error: Cannot redeclare class p (previously declared in %sbug67215.p.php:%d) in %sbug67215.p.php on line %d
2 changes: 1 addition & 1 deletion ext/opcache/tests/gh8846.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ echo file_get_contents('http://' . PHP_CLI_SERVER_ADDRESS . '/gh8846-index.php?s
--EXPECTF--
bool(true)
<br />
<b>Fatal error</b>: Cannot declare class Foo, because the name is already in use in <b>%sgh8846-2.inc</b> on line <b>%d</b><br />
<b>Fatal error</b>: Cannot redeclare class Foo (previously declared in %sgh8846-1.inc:2) in <b>%sgh8846-2.inc</b> on line <b>%d</b><br />

bool(true)
Ok
4 changes: 1 addition & 3 deletions ext/opcache/zend_accelerator_util_funcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,7 @@ static zend_always_inline void _zend_accel_class_hash_copy(HashTable *target, Ha
CG(in_compilation) = 1;
zend_set_compiled_filename(ce1->info.user.filename);
CG(zend_lineno) = ce1->info.user.line_start;
zend_error_noreturn(E_ERROR,
"Cannot declare %s %s, because the name is already in use",
zend_get_object_type(ce1), ZSTR_VAL(ce1->name));
zend_class_redeclaration_error(E_ERROR, Z_PTR_P(t));
return;
}
continue;
Expand Down
8 changes: 4 additions & 4 deletions scripts/dev/bless_tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ function getFiles(array $dirsOrFiles): \Iterator {
}

function normalizeOutput(string $out): string {
$out = preg_replace('/in (\/|[A-Z]:\\\\).+ on line \d+/m', 'in %s on line %d', $out);
$out = preg_replace('/in (\/|[A-Z]:\\\\).+:\d+$/m', 'in %s:%d', $out);
$out = preg_replace('/\{closure:(\/|[A-Z]:\\\\).+:\d+\}/', '{closure:%s:%d}', $out);
$out = preg_replace('/in (\/|[A-Z]:\\\\)\S+? on line \d+/m', 'in %s on line %d', $out);
$out = preg_replace('/in (\/|[A-Z]:\\\\)\S+:\d+(?=$|\))/m', 'in %s:%d', $out);
$out = preg_replace('/\{closure:(\/|[A-Z]:\\\\)\S+:\d+\}/', '{closure:%s:%d}', $out);
$out = preg_replace('/object\(([A-Za-z0-9]*)\)#\d+/', 'object($1)#%d', $out);
$out = preg_replace('/^#(\d+) (\/|[A-Z]:\\\\).+\(\d+\):/m', '#$1 %s(%d):', $out);
$out = preg_replace('/^#(\d+) (\/|[A-Z]:\\\\)\S+\(\d+\):/m', '#$1 %s(%d):', $out);
$out = preg_replace('/Resource id #\d+/', 'Resource id #%d', $out);
$out = preg_replace('/resource\(\d+\) of type/', 'resource(%d) of type', $out);
$out = preg_replace(
Expand Down