mirror of
https://github.com/php/php-src.git
synced 2024-09-21 09:57:23 +00:00
Change "Cannot redeclare class X" into "Cannot redeclare class/interface/trait X", meaning that the following:
C:\> php -r "trait A { } trait A { }" Will now properly print "Cannot redeclare trait A" instead of "Cannot redeclare class A" to make error messages a tiny bit clearer. Admittedly, a better solution can most likely be made by actually telling what the colliding object is a type of. Internally this adds a new function: zend_get_object_type()
This commit is contained in:
parent
a3d2f9b600
commit
927d53fda4
@ -11,4 +11,4 @@ class b { }
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: Cannot redeclare class b in %s on line %d
|
||||
Warning: Cannot redeclare interface b in %s on line %d
|
||||
|
@ -4137,6 +4137,18 @@ ZEND_API void zend_ctor_make_null(zend_execute_data *execute_data) /* {{{ */
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
ZEND_API char *zend_get_object_type(zend_class_entry *ce) /* {{{ */
|
||||
{
|
||||
if(ce->ce_flags & ZEND_ACC_TRAIT) {
|
||||
return "trait";
|
||||
} else if (ce->ce_flags & ZEND_ACC_INTERFACE) {
|
||||
return "interface";
|
||||
} else {
|
||||
return "class";
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
|
@ -540,6 +540,8 @@ ZEND_API zend_string *zend_resolve_method_name(zend_class_entry *ce, zend_functi
|
||||
|
||||
ZEND_API void zend_ctor_make_null(zend_execute_data *execute_data);
|
||||
|
||||
ZEND_API char *zend_get_object_type(zend_class_entry *ce);
|
||||
|
||||
#define add_method(arg, key, method) add_assoc_function((arg), (key), (method))
|
||||
|
||||
ZEND_API ZEND_FUNCTION(display_disabled_function);
|
||||
|
@ -1536,7 +1536,7 @@ ZEND_FUNCTION(class_alias)
|
||||
if (zend_register_class_alias_ex(alias_name, alias_name_len, ce) == SUCCESS) {
|
||||
RETURN_TRUE;
|
||||
} else {
|
||||
zend_error(E_WARNING, "Cannot redeclare class %s", alias_name);
|
||||
zend_error(E_WARNING, "Cannot redeclare %s %s", zend_get_object_type(ce), alias_name);
|
||||
RETURN_FALSE;
|
||||
}
|
||||
} else {
|
||||
|
@ -1002,7 +1002,7 @@ ZEND_API zend_class_entry *do_bind_class(const zend_op_array* op_array, const ze
|
||||
* so we shut up about it. This allows the if (!defined('FOO')) { return; }
|
||||
* approach to work.
|
||||
*/
|
||||
zend_error_noreturn(E_COMPILE_ERROR, "Cannot redeclare class %s", ce->name->val);
|
||||
zend_error_noreturn(E_COMPILE_ERROR, "Cannot redeclare %s %s", zend_get_object_type(ce), ce->name->val);
|
||||
}
|
||||
return NULL;
|
||||
} else {
|
||||
@ -1036,13 +1036,13 @@ ZEND_API zend_class_entry *do_bind_inherited_class(const zend_op_array *op_array
|
||||
* so we shut up about it. This allows the if (!defined('FOO')) { return; }
|
||||
* approach to work.
|
||||
*/
|
||||
zend_error_noreturn(E_COMPILE_ERROR, "Cannot redeclare class %s", Z_STRVAL_P(op2));
|
||||
zend_error_noreturn(E_COMPILE_ERROR, "Cannot redeclare %s %s", zend_get_object_type(Z_OBJCE_P(op2)), Z_STRVAL_P(op2));
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (zend_hash_exists(class_table, Z_STR_P(op2))) {
|
||||
zend_error_noreturn(E_COMPILE_ERROR, "Cannot redeclare class %s", ce->name->val);
|
||||
zend_error_noreturn(E_COMPILE_ERROR, "Cannot redeclare %s %s", zend_get_object_type(ce), ce->name->val);
|
||||
}
|
||||
|
||||
zend_do_inheritance(ce, parent_ce);
|
||||
@ -1051,7 +1051,7 @@ ZEND_API zend_class_entry *do_bind_inherited_class(const zend_op_array *op_array
|
||||
|
||||
/* Register the derived class */
|
||||
if (zend_hash_add_ptr(class_table, Z_STR_P(op2), ce) == NULL) {
|
||||
zend_error_noreturn(E_COMPILE_ERROR, "Cannot redeclare class %s", ce->name->val);
|
||||
zend_error_noreturn(E_COMPILE_ERROR, "Cannot redeclare %s %s", zend_get_object_type(ce), ce->name->val);
|
||||
}
|
||||
return ce;
|
||||
}
|
||||
|
@ -755,7 +755,7 @@ failure:
|
||||
CG(in_compilation) = 1;
|
||||
zend_set_compiled_filename(ce1->info.user.filename);
|
||||
CG(zend_lineno) = ce1->info.user.line_start;
|
||||
zend_error(E_ERROR, "Cannot redeclare class %s", ce1->name->val);
|
||||
zend_error(E_ERROR, "Cannot redeclare %s %s", zend_get_object_type(ce1), ce1->name->val);
|
||||
}
|
||||
|
||||
#ifdef __SSE2__
|
||||
|
Loading…
Reference in New Issue
Block a user