]> granicus.if.org Git - php/commitdiff
Make duplicate class constant error for internal class
authorNikita Popov <nikic@php.net>
Thu, 10 Dec 2015 21:22:49 +0000 (22:22 +0100)
committerNikita Popov <nikic@php.net>
Thu, 10 Dec 2015 21:22:49 +0000 (22:22 +0100)
And drop two duplicate constant declarations from intl. These
were leaking previously.

Zend/zend_API.c
Zend/zend_compile.c
ext/intl/calendar/calendar_class.cpp

index fc49f3369e76f5225717e8dd1fae815f11f8b77c..8003fd79aa0b6239e97fc43a899d796175d4ba63 100644 (file)
@@ -3749,7 +3749,7 @@ ZEND_API int zend_declare_class_constant_ex(zend_class_entry *ce, zend_string *n
        }
 
        if (zend_string_equals_literal_ci(name, "class")) {
-               zend_error((ce->type == ZEND_INTERNAL_CLASS) ? E_CORE_ERROR : E_COMPILE_ERROR,
+               zend_error_noreturn(ce->type == ZEND_INTERNAL_CLASS ? E_CORE_ERROR : E_COMPILE_ERROR,
                                "A class constant must not be called 'class'; it is reserved for class name fetching");
        }
 
@@ -3765,8 +3765,13 @@ ZEND_API int zend_declare_class_constant_ex(zend_class_entry *ce, zend_string *n
        if (Z_CONSTANT_P(value)) {
                ce->ce_flags &= ~ZEND_ACC_CONSTANTS_UPDATED;
        }
-       return zend_hash_add_ptr(&ce->constants_table, name, c) ?
-               SUCCESS : FAILURE;
+
+       if (!zend_hash_add_ptr(&ce->constants_table, name, c)) {
+               zend_error_noreturn(ce->type == ZEND_INTERNAL_CLASS ? E_CORE_ERROR : E_COMPILE_ERROR,
+                       "Cannot redefine class constant %s::%s", ZSTR_VAL(ce->name), ZSTR_VAL(name));
+       }
+
+       return SUCCESS;
 }
 /* }}} */
 
index 2e50271a7f4706b51ba3de87c83cdd3c3269ec69..329545138dfcd9ce6cab572038c9de64ea5f0926 100644 (file)
@@ -5231,10 +5231,7 @@ void zend_compile_class_const_decl(zend_ast *ast) /* {{{ */
                zend_const_expr_to_zval(&value_zv, value_ast);
 
                name = zend_new_interned_string_safe(name);
-               if (zend_declare_class_constant_ex(ce, name, &value_zv, ast->attr, doc_comment) != SUCCESS) {
-                       zend_error_noreturn(E_COMPILE_ERROR, "Cannot redefine class constant %s::%s",
-                               ZSTR_VAL(ce->name), ZSTR_VAL(name));
-               }
+               zend_declare_class_constant_ex(ce, name, &value_zv, ast->attr, doc_comment);
        }
 }
 /* }}} */
index 6b6feef8d98c8798a18a252b37674236aa8ed44d..1f3a68b8021337cff9b5daf50404319595989f40 100644 (file)
@@ -505,8 +505,6 @@ void calendar_register_IntlCalendar_class(void)
        CALENDAR_DECL_LONG_CONST("FIELD_AM_PM",                                 UCAL_AM_PM);
        CALENDAR_DECL_LONG_CONST("FIELD_HOUR",                                  UCAL_HOUR);
        CALENDAR_DECL_LONG_CONST("FIELD_HOUR_OF_DAY",                   UCAL_HOUR_OF_DAY);
-       CALENDAR_DECL_LONG_CONST("FIELD_HOUR",                                  UCAL_HOUR);
-       CALENDAR_DECL_LONG_CONST("FIELD_HOUR_OF_DAY",                   UCAL_HOUR_OF_DAY);
        CALENDAR_DECL_LONG_CONST("FIELD_MINUTE",                                UCAL_MINUTE);
        CALENDAR_DECL_LONG_CONST("FIELD_SECOND",                                UCAL_SECOND);
        CALENDAR_DECL_LONG_CONST("FIELD_MILLISECOND",                   UCAL_MILLISECOND);