Re: com php-src: Change "Cannot redeclare class X" into "Cannot redeclare class/interface/trait X", meaning that the following::
Zend/tests/class_alias_004.phpt Zend/tests/class_alias_010.phpt Zend/zend_API.c Zend/zend_API.h Zend/zend_builtin_functions.c Zend/zend_compile.c
ext/opcache/zend_accelerator_util_funcs.c
| From: | Michael Wallner | Date: | Wed, 25 Mar 2015 05:57:12 +0000 |
| Subject: | Re: com php-src: Change "Cannot redeclare class X" into "Cannot redeclare class/interface/trait X", meaning that the following:: Zend/tests/class_alias_004.phpt Zend/tests/class_alias_010.phpt Zend/zend_API.c Zend/zend_API.h Zend/zend_builtin_functions.c Zend/zend_compile.c ext/opcache/zend_accelerator_util_funcs.c |
||
| References: | 1 | Groups: | php.cvs |
| Request: | Send a blank email to php-cvs+get-85861@lists.php.net to get a copy of this message | ||
Hi Kalle!
On 25 Mar 2015 06:33, "Kalle Sommer Nielsen" <kalle@php.net> wrote:
>
> Commit: 927d53fda428205f0ec620d145890091069d8f75
> Author: Kalle Sommer Nielsen <kalle@php.net> Wed, 25 Mar 2015
06:31:11 +0100
> Parents: a3d2f9b600c11a651961e00013a682d4d07ce401
> Branches: master
>
> Link:
http://git.php.net/?p=php-src.git;a=commitdiff;h=927d53fda428205f0ec620d145890091069d8f75
>
> Log:
> 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()
>
> Changed paths:
> M Zend/tests/class_alias_004.phpt
> M Zend/tests/class_alias_010.phpt
> M Zend/zend_API.c
> M Zend/zend_API.h
> M Zend/zend_builtin_functions.c
> M Zend/zend_compile.c
> M ext/opcache/zend_accelerator_util_funcs.c
>
>
> Diff:
> diff --git a/Zend/tests/class_alias_004.phpt
b/Zend/tests/class_alias_004.phpt
> index b7dbabd..b9370dd 100644
> --- a/Zend/tests/class_alias_004.phpt
> +++ b/Zend/tests/class_alias_004.phpt
> @@ -12,4 +12,4 @@ class_alias('foo', 'test');
>
> ?>
> --EXPECTF--
> -Warning: Cannot redeclare class test in %s on line %d
> +Warning: Cannot redeclare class test in %s on line %d
> \ No newline at end of file
> diff --git a/Zend/tests/class_alias_010.phpt
b/Zend/tests/class_alias_010.phpt
> index 38590b6..0eff174 100644
> --- a/Zend/tests/class_alias_010.phpt
> +++ b/Zend/tests/class_alias_010.phpt
> @@ -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
> diff --git a/Zend/zend_API.c b/Zend/zend_API.c
> index 6dd7bca..2f62fa0 100644
> --- a/Zend/zend_API.c
> +++ b/Zend/zend_API.c
> @@ -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";
> + }
> +}
> +/* }}} */
> +
Looks like both, the return type as well as the argument, can be marked as
const.
> /*
> * Local variables:
> * tab-width: 4
> diff --git a/Zend/zend_API.h b/Zend/zend_API.h
> index 7513fd0..deaec02 100644
> --- a/Zend/zend_API.h
> +++ b/Zend/zend_API.h
> @@ -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);
> diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c
> index a620e45..ecb9078 100644
> --- a/Zend/zend_builtin_functions.c
> +++ b/Zend/zend_builtin_functions.c
> @@ -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 {
> diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
> index ffe1b92..f8ac526 100644
> --- a/Zend/zend_compile.c
> +++ b/Zend/zend_compile.c
> @@ -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;
> }
> diff --git a/ext/opcache/zend_accelerator_util_funcs.c
b/ext/opcache/zend_accelerator_util_funcs.c
> index 20b097b..bd373d9 100644
> --- a/ext/opcache/zend_accelerator_util_funcs.c
> +++ b/ext/opcache/zend_accelerator_util_funcs.c
> @@ -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__
>
>
> --
> PHP CVS Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>