diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c index eab2a0399011..63517322b470 100644 --- a/Zend/zend_builtin_functions.c +++ b/Zend/zend_builtin_functions.c @@ -82,10 +82,10 @@ ZEND_FUNCTION(clone) /* clone() also exists as the ZEND_CLONE OPcode and both implementations must be kept in sync. */ - zend_class_entry *scope = zend_get_executed_scope(); + const zend_class_entry *scope = zend_get_executed_scope(); - zend_class_entry *ce = zobj->ce; - zend_function *clone = ce->clone; + const zend_class_entry *ce = zobj->ce; + const zend_function *clone = ce->clone; if (UNEXPECTED(zobj->handlers->clone_obj == NULL)) { zend_throw_error(NULL, "Trying to clone an uncloneable object of class %s", ZSTR_VAL(ce->name)); @@ -237,7 +237,7 @@ ZEND_FUNCTION(gc_status) /* {{{ Get the number of arguments that were passed to the function */ ZEND_FUNCTION(func_num_args) { - zend_execute_data *ex = EX(prev_execute_data); + const zend_execute_data *ex = EX(prev_execute_data); ZEND_PARSE_PARAMETERS_NONE(); @@ -247,7 +247,7 @@ ZEND_FUNCTION(func_num_args) } if (zend_forbid_dynamic_call() == FAILURE) { - RETURN_LONG(-1); + RETURN_THROWS(); } RETURN_LONG(ZEND_CALL_NUM_ARGS(ex)); @@ -501,7 +501,7 @@ ZEND_FUNCTION(error_reporting) } /* }}} */ -static bool validate_constant_array_argument(HashTable *ht, int argument_number) /* {{{ */ +static bool validate_constant_array_argument(HashTable *ht, uint32_t argument_number) /* {{{ */ { bool ret = true; zval *val; @@ -525,7 +525,7 @@ static bool validate_constant_array_argument(HashTable *ht, int argument_number) } /* }}} */ -static void copy_constant_array(zval *dst, zval *src) /* {{{ */ +static void copy_constant_array(zval *dst, const zval *src) /* {{{ */ { zend_string *key; zend_ulong idx; @@ -595,11 +595,7 @@ ZEND_FUNCTION(define) /* non persistent */ ZEND_CONSTANT_SET_FLAGS(&c, 0, PHP_USER_CONSTANT); c.name = zend_string_copy(name); - if (zend_register_constant(&c) != NULL) { - RETURN_TRUE; - } else { - RETURN_FALSE; - } + RETURN_BOOL(zend_register_constant(&c) != NULL); } /* }}} */ @@ -613,11 +609,7 @@ ZEND_FUNCTION(defined) Z_PARAM_STR(name) ZEND_PARSE_PARAMETERS_END(); - if (zend_get_constant_ex(name, zend_get_executed_scope(), ZEND_FETCH_CLASS_SILENT)) { - RETURN_TRUE; - } else { - RETURN_FALSE; - } + RETURN_BOOL(zend_get_constant_ex(name, zend_get_executed_scope(), ZEND_FETCH_CLASS_SILENT)); } /* }}} */ @@ -631,7 +623,7 @@ ZEND_FUNCTION(get_class) } if (!obj) { - zend_class_entry *scope = zend_get_executed_scope(); + const zend_class_entry *scope = zend_get_executed_scope(); if (scope) { zend_error(E_DEPRECATED, "Calling get_class() without arguments is deprecated"); @@ -652,7 +644,7 @@ ZEND_FUNCTION(get_class) /* {{{ Retrieves the "Late Static Binding" class name */ ZEND_FUNCTION(get_called_class) { - zend_class_entry *called_scope; + const zend_class_entry *called_scope; ZEND_PARSE_PARAMETERS_NONE(); @@ -697,9 +689,7 @@ static void is_a_impl(INTERNAL_FUNCTION_PARAMETERS, bool only_subclass) /* {{{ * zval *obj; zend_string *class_name; zend_class_entry *instance_ce; - zend_class_entry *ce; bool allow_string = only_subclass; - bool retval; ZEND_PARSE_PARAMETERS_START(2, 3) Z_PARAM_ZVAL(obj) @@ -726,21 +716,19 @@ static void is_a_impl(INTERNAL_FUNCTION_PARAMETERS, bool only_subclass) /* {{{ * } if (!only_subclass && EXPECTED(zend_string_equals(instance_ce->name, class_name))) { - retval = 1; - } else { - ce = zend_lookup_class_ex(class_name, NULL, ZEND_FETCH_CLASS_NO_AUTOLOAD); - if (!ce) { - retval = 0; - } else { - if (only_subclass && instance_ce == ce) { - retval = 0; - } else { - retval = instanceof_function(instance_ce, ce); - } - } + RETURN_TRUE; + } + + const zend_class_entry *ce = zend_lookup_class_ex(class_name, NULL, ZEND_FETCH_CLASS_NO_AUTOLOAD); + if (!ce) { + RETURN_FALSE; + } + + if (only_subclass && instance_ce == ce) { + RETURN_FALSE; } - RETURN_BOOL(retval); + RETURN_BOOL(instanceof_function(instance_ce, ce)); } /* }}} */ @@ -759,7 +747,7 @@ ZEND_FUNCTION(is_a) /* }}} */ /* {{{ add_class_vars */ -static void add_class_vars(zend_class_entry *scope, zend_class_entry *ce, bool statics, zval *return_value) +static void add_class_vars(const zend_class_entry *scope, zend_class_entry *ce, bool statics, zval *return_value) { zend_property_info *prop_info; zval *prop, prop_copy; @@ -810,7 +798,7 @@ static void add_class_vars(zend_class_entry *scope, zend_class_entry *ce, bool s /* {{{ Returns an array of default properties of the class. */ ZEND_FUNCTION(get_class_vars) { - zend_class_entry *ce = NULL, *scope; + zend_class_entry *ce = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS(), "C", &ce) == FAILURE) { RETURN_THROWS(); @@ -823,7 +811,7 @@ ZEND_FUNCTION(get_class_vars) } } - scope = zend_get_executed_scope(); + const zend_class_entry *scope = zend_get_executed_scope(); add_class_vars(scope, ce, false, return_value); add_class_vars(scope, ce, true, return_value); } @@ -949,7 +937,6 @@ ZEND_FUNCTION(get_class_methods) { zval method_name; zend_class_entry *ce = NULL; - zend_class_entry *scope; zend_function *mptr; ZEND_PARSE_PARAMETERS_START(1, 1) @@ -957,7 +944,7 @@ ZEND_FUNCTION(get_class_methods) ZEND_PARSE_PARAMETERS_END(); array_init(return_value); - scope = zend_get_executed_scope(); + const zend_class_entry *scope = zend_get_executed_scope(); ZEND_HASH_MAP_FOREACH_PTR(&ce->function_table, mptr) { if (zend_check_method_accessible(mptr, scope)) { @@ -1032,10 +1019,9 @@ ZEND_FUNCTION(method_exists) } /* }}} */ -static void _property_exists(zval *return_value, zval *object, zend_string *property) +static void _property_exists(zval *return_value, const zval *object, zend_string *property) { zend_class_entry *ce; - zend_property_info *property_info; if (Z_TYPE_P(object) == IS_STRING) { ce = zend_lookup_class(Z_STR_P(object)); @@ -1049,18 +1035,17 @@ static void _property_exists(zval *return_value, zval *object, zend_string *prop RETURN_THROWS(); } - property_info = zend_hash_find_ptr(&ce->properties_info, property); + const zend_property_info *property_info = zend_hash_find_ptr(&ce->properties_info, property); if (property_info != NULL && (!(property_info->flags & ZEND_ACC_PRIVATE) || property_info->ce == ce)) { RETURN_TRUE; } - if (Z_TYPE_P(object) == IS_OBJECT && - Z_OBJ_HANDLER_P(object, has_property)(Z_OBJ_P(object), property, ZEND_PROPERTY_EXISTS, NULL)) { - RETURN_TRUE; - } - RETURN_FALSE; + RETURN_BOOL( + Z_TYPE_P(object) == IS_OBJECT && + Z_OBJ_HANDLER_P(object, has_property)(Z_OBJ_P(object), property, ZEND_PROPERTY_EXISTS, NULL) + ); } /* {{{ Checks if the object or class has a property */ @@ -1120,11 +1105,7 @@ static inline void _class_exists_impl(zval *return_value, zend_string *name, boo ce = zend_lookup_class(name); } - if (ce) { - RETURN_BOOL(((ce->ce_flags & flags) == flags) && !(ce->ce_flags & skip_flags)); - } else { - RETURN_FALSE; - } + RETURN_BOOL(ce && ((ce->ce_flags & flags) == flags) && !(ce->ce_flags & skip_flags)); } /* {{{ */ @@ -1430,7 +1411,6 @@ static inline void get_declared_class_impl(INTERNAL_FUNCTION_PARAMETERS, int fla { zend_string *key; zval *zv; - zend_class_entry *ce; ZEND_PARSE_PARAMETERS_NONE(); @@ -1438,7 +1418,7 @@ static inline void get_declared_class_impl(INTERNAL_FUNCTION_PARAMETERS, int fla zend_hash_real_init_packed(Z_ARRVAL_P(return_value)); ZEND_HASH_FILL_PACKED(Z_ARRVAL_P(return_value)) { ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(EG(class_table), key, zv) { - ce = Z_PTR_P(zv); + const zend_class_entry *ce = Z_PTR_P(zv); if ((ce->ce_flags & (ZEND_ACC_LINKED|ZEND_ACC_INTERFACE|ZEND_ACC_TRAIT)) == flags && key && ZSTR_VAL(key)[0] != 0) { @@ -1556,7 +1536,7 @@ ZEND_FUNCTION(get_resource_type) if (resource_type) { RETURN_STRING(resource_type); } else { - RETURN_STRING("Unknown"); + RETURN_STR(ZSTR_KNOWN(ZEND_STR_UNKNOWN_CAPITALIZED)); } } /* }}} */ @@ -1893,7 +1873,7 @@ ZEND_API void zend_fetch_debug_backtrace(zval *return_value, int skip_last, int zend_execute_data *call, *last_call = NULL; zend_object *object; bool fake_frame = false; - int lineno, frameno = 0; + int frameno = 0; zend_function *func; zend_string *filename; zend_string *include_filename = NULL; @@ -1914,12 +1894,12 @@ ZEND_API void zend_fetch_debug_backtrace(zval *return_value, int skip_last, int EG(filename_override) = NULL; EG(lineno_override) = -1; - zend_string *filename = zend_get_executed_filename_ex(); - zend_long lineno = zend_get_executed_lineno(); - if (filename && (!zend_string_equals(filename, filename_override) || lineno != lineno_override)) { + zend_string *executed_filename = zend_get_executed_filename_ex(); + uint32_t lineno = zend_get_executed_lineno(); + if (executed_filename && (!zend_string_equals(executed_filename, filename_override) || lineno != lineno_override)) { stack_frame = zend_new_array(8); zend_hash_real_init_mixed(stack_frame); - ZVAL_STR_COPY(&tmp, filename); + ZVAL_STR_COPY(&tmp, executed_filename); _zend_hash_append_ex(stack_frame, ZSTR_KNOWN(ZEND_STR_FILE), &tmp, 1); ZVAL_LONG(&tmp, lineno); _zend_hash_append_ex(stack_frame, ZSTR_KNOWN(ZEND_STR_LINE), &tmp, 1); @@ -1982,19 +1962,21 @@ ZEND_API void zend_fetch_debug_backtrace(zval *return_value, int skip_last, int zval *arg = zend_get_zval_ptr(op_data, op_data->op1_type, &op_data->op1, call); if (Z_TYPE_P(arg) == IS_UNDEF) goto not_frameless_call; } - zend_function *func = ZEND_FLF_FUNC(opline); + zend_function *frameless_func = ZEND_FLF_FUNC(opline); /* Assume frameless functions are not recursive with themselves. * This condition may be true when observers are enabled: * Observers will put a call frame on top of the frameless opcode. */ - if (last_call && last_call->func == func) { + if (last_call && last_call->func == frameless_func) { goto not_frameless_call; } stack_frame = zend_new_array(8); zend_hash_real_init_mixed(stack_frame); - ZVAL_STR_COPY(&tmp, func->common.function_name); + ZVAL_STR_COPY(&tmp, frameless_func->common.function_name); _zend_hash_append_ex(stack_frame, ZSTR_KNOWN(ZEND_STR_FUNCTION), &tmp, 1); /* Steal file and line from the previous frame. */ if (call->func && ZEND_USER_CODE(call->func->common.type)) { + uint32_t lineno; + filename = call->func->op_array.filename; if (call->opline->opcode == ZEND_HANDLE_EXCEPTION) { if (EG(opline_before_exception)) { @@ -2046,6 +2028,8 @@ ZEND_API void zend_fetch_debug_backtrace(zval *return_value, int skip_last, int zend_hash_real_init_mixed(stack_frame); if (prev && prev->func && ZEND_USER_CODE(prev->func->common.type)) { + uint32_t lineno; + filename = prev->func->op_array.filename; if (prev->opline->opcode == ZEND_HANDLE_EXCEPTION) { if (EG(opline_before_exception)) { @@ -2230,11 +2214,7 @@ ZEND_FUNCTION(extension_loaded) } lcname = zend_string_tolower(extension_name); - if (zend_hash_exists(&module_registry, lcname)) { - RETVAL_TRUE; - } else { - RETVAL_FALSE; - } + RETVAL_BOOL(zend_hash_exists(&module_registry, lcname)); zend_string_release_ex(lcname, 0); } /* }}} */