diff --git a/UPGRADING.INTERNALS b/UPGRADING.INTERNALS index 8f62015f733fd..dd8cab47f1a06 100644 --- a/UPGRADING.INTERNALS +++ b/UPGRADING.INTERNALS @@ -86,6 +86,8 @@ PHP 8.4 INTERNALS UPGRADE NOTES for internal functions. If you need a cache slot for both internal and user functions, you may obtain a slot for each through the corresponding function. +* zend_is_true now returns bool rather than int. Note that on PHP 8 this has + always returned 0 or 1, so conversion should be trivial. ======================== 2. Build system changes diff --git a/Zend/Optimizer/pass1.c b/Zend/Optimizer/pass1.c index ba2bf188102c2..7543c15341c97 100644 --- a/Zend/Optimizer/pass1.c +++ b/Zend/Optimizer/pass1.c @@ -309,7 +309,7 @@ void zend_optimizer_pass1(zend_op_array *op_array, zend_optimizer_ctx *ctx) case ZEND_JMPZ: case ZEND_JMPNZ: if (opline->op1_type == IS_CONST) { - int should_jmp = zend_is_true(&ZEND_OP1_LITERAL(opline)); + bool should_jmp = zend_is_true(&ZEND_OP1_LITERAL(opline)); if (opline->opcode == ZEND_JMPZ) { should_jmp = !should_jmp; diff --git a/Zend/zend_object_handlers.c b/Zend/zend_object_handlers.c index f72cb76489abd..158b937238573 100644 --- a/Zend/zend_object_handlers.c +++ b/Zend/zend_object_handlers.c @@ -1057,11 +1057,12 @@ ZEND_API void zend_std_write_dimension(zend_object *object, zval *offset, zval * } /* }}} */ +// todo: make zend_std_has_dimension return bool as well ZEND_API int zend_std_has_dimension(zend_object *object, zval *offset, int check_empty) /* {{{ */ { zend_class_entry *ce = object->ce; zval retval, tmp_offset; - int result; + bool result; zend_class_arrayaccess_funcs *funcs = ce->arrayaccess_funcs_ptr; if (EXPECTED(funcs)) { @@ -1081,6 +1082,7 @@ ZEND_API int zend_std_has_dimension(zend_object *object, zval *offset, int check zend_bad_array_access(ce); return 0; } + return result; } /* }}} */ @@ -1810,9 +1812,10 @@ ZEND_API int zend_objects_not_comparable(zval *o1, zval *o2) return ZEND_UNCOMPARABLE; } +// todo: make zend_std_has_property return bool as well ZEND_API int zend_std_has_property(zend_object *zobj, zend_string *name, int has_set_exists, void **cache_slot) /* {{{ */ { - int result; + bool result; zval *value = NULL; uintptr_t property_offset; const zend_property_info *prop_info = NULL; @@ -1826,7 +1829,7 @@ ZEND_API int zend_std_has_property(zend_object *zobj, zend_string *name, int has } if (UNEXPECTED(Z_PROP_FLAG_P(value) & IS_PROP_UNINIT)) { /* Skip __isset() for uninitialized typed properties */ - result = 0; + result = false; goto exit; } } else if (EXPECTED(IS_DYNAMIC_PROPERTY_OFFSET(property_offset))) { @@ -1862,17 +1865,17 @@ ZEND_API int zend_std_has_property(zend_object *zobj, zend_string *name, int has result = (Z_TYPE_P(value) != IS_NULL); } else { ZEND_ASSERT(has_set_exists == ZEND_PROPERTY_EXISTS); - result = 1; + result = true; } goto exit; } } } else if (UNEXPECTED(EG(exception))) { - result = 0; + result = false; goto exit; } - result = 0; + result = false; if ((has_set_exists != ZEND_PROPERTY_EXISTS) && zobj->ce->__isset) { uint32_t *guard = zend_get_property_guard(zobj, name); @@ -1893,7 +1896,7 @@ ZEND_API int zend_std_has_property(zend_object *zobj, zend_string *name, int has result = i_zend_is_true(&rv); zval_ptr_dtor(&rv); } else { - result = 0; + result = false; } } (*guard) &= ~IN_ISSET; diff --git a/Zend/zend_operators.c b/Zend/zend_operators.c index f825e63ff699b..fc124d1b20999 100644 --- a/Zend/zend_operators.c +++ b/Zend/zend_operators.c @@ -2818,9 +2818,9 @@ ZEND_API zend_result ZEND_FASTCALL decrement_function(zval *op1) /* {{{ */ } /* }}} */ -ZEND_API int ZEND_FASTCALL zend_is_true(const zval *op) /* {{{ */ +ZEND_API bool ZEND_FASTCALL zend_is_true(const zval *op) /* {{{ */ { - return (int) i_zend_is_true(op); + return i_zend_is_true(op); } /* }}} */ diff --git a/Zend/zend_operators.h b/Zend/zend_operators.h index 899567a953c63..e9f48bc496f96 100644 --- a/Zend/zend_operators.h +++ b/Zend/zend_operators.h @@ -372,7 +372,7 @@ static zend_always_inline bool try_convert_to_string(zval *op) { #define convert_to_string(op) if (Z_TYPE_P(op) != IS_STRING) { _convert_to_string((op)); } -ZEND_API int ZEND_FASTCALL zend_is_true(const zval *op); +ZEND_API bool ZEND_FASTCALL zend_is_true(const zval *op); ZEND_API bool ZEND_FASTCALL zend_object_is_true(const zval *op); #define zval_is_true(op) \ diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index 9824a94e90b04..8327fe95f7aea 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -7313,8 +7313,7 @@ ZEND_VM_HANDLER(114, ZEND_ISSET_ISEMPTY_VAR, CONST|TMPVAR|CV, UNUSED, VAR_FETCH| { USE_OPLINE zval *value; - /* Should be bool result? as below got: result = (opline->extended_value & ZEND_ISEMPTY) */ - int result; + bool result; zval *varname; zend_string *name, *tmp_name; HashTable *target_symbol_table; @@ -7351,7 +7350,7 @@ ZEND_VM_HANDLER(114, ZEND_ISSET_ISEMPTY_VAR, CONST|TMPVAR|CV, UNUSED, VAR_FETCH| } } - ZEND_VM_SMART_BRANCH(result, 1); + ZEND_VM_SMART_BRANCH(result, true); } /* No specialization for op_types (CONST|TMPVAR|CV, UNUSED|CLASS_FETCH|CONST|VAR) */ diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index 6ca5a757f7863..e6010c96933e4 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -10856,8 +10856,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ISSET_ISEMPTY_VAR_SPEC_CONST_U { USE_OPLINE zval *value; - /* Should be bool result? as below got: result = (opline->extended_value & ZEND_ISEMPTY) */ - int result; + bool result; zval *varname; zend_string *name, *tmp_name; HashTable *target_symbol_table; @@ -10893,7 +10892,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ISSET_ISEMPTY_VAR_SPEC_CONST_U } } - ZEND_VM_SMART_BRANCH(result, 1); + ZEND_VM_SMART_BRANCH(result, true); } /* No specialization for op_types (CONST|TMPVAR|CV, UNUSED|CLASS_FETCH|CONST|VAR) */ @@ -18221,8 +18220,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ISSET_ISEMPTY_VAR_SPEC_TMPVAR_ { USE_OPLINE zval *value; - /* Should be bool result? as below got: result = (opline->extended_value & ZEND_ISEMPTY) */ - int result; + bool result; zval *varname; zend_string *name, *tmp_name; HashTable *target_symbol_table; @@ -18259,7 +18257,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ISSET_ISEMPTY_VAR_SPEC_TMPVAR_ } } - ZEND_VM_SMART_BRANCH(result, 1); + ZEND_VM_SMART_BRANCH(result, true); } /* No specialization for op_types (CONST|TMPVAR|CV, UNUSED|CLASS_FETCH|CONST|VAR) */ @@ -49703,8 +49701,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ISSET_ISEMPTY_VAR_SPEC_CV_UNUS { USE_OPLINE zval *value; - /* Should be bool result? as below got: result = (opline->extended_value & ZEND_ISEMPTY) */ - int result; + bool result; zval *varname; zend_string *name, *tmp_name; HashTable *target_symbol_table; @@ -49740,7 +49737,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ISSET_ISEMPTY_VAR_SPEC_CV_UNUS } } - ZEND_VM_SMART_BRANCH(result, 1); + ZEND_VM_SMART_BRANCH(result, true); } /* No specialization for op_types (CONST|TMPVAR|CV, UNUSED|CLASS_FETCH|CONST|VAR) */ diff --git a/Zend/zend_weakrefs.c b/Zend/zend_weakrefs.c index 006421f725a21..3af7a386ad29f 100644 --- a/Zend/zend_weakrefs.c +++ b/Zend/zend_weakrefs.c @@ -405,6 +405,7 @@ static void zend_weakmap_write_dimension(zend_object *object, zval *offset, zval zend_hash_index_add_new(&wm->ht, obj_key, value); } +// todo: make zend_weakmap_has_dimension return bool as well /* int return and check_empty due to Object Handler API */ static int zend_weakmap_has_dimension(zend_object *object, zval *offset, int check_empty) { diff --git a/ext/dom/php_dom.c b/ext/dom/php_dom.c index 0f2d2b67f512e..7c7505015055f 100644 --- a/ext/dom/php_dom.c +++ b/ext/dom/php_dom.c @@ -404,12 +404,13 @@ zval *dom_write_property(zend_object *object, zend_string *name, zval *value, vo return zend_std_write_property(object, name, value, cache_slot); } +// todo: make dom_property_exists return bool as well /* {{{ dom_property_exists */ static int dom_property_exists(zend_object *object, zend_string *name, int check_empty, void **cache_slot) { dom_object *obj = php_dom_obj_from_obj(object); dom_prop_handler *hnd = NULL; - int retval = 0; + bool retval = false; if (obj->prop_handler != NULL) { hnd = zend_hash_find_ptr(obj->prop_handler, name); @@ -418,7 +419,7 @@ static int dom_property_exists(zend_object *object, zend_string *name, int check zval tmp; if (check_empty == 2) { - retval = 1; + retval = true; } else if (hnd->read_func(obj, &tmp) == SUCCESS) { if (check_empty == 1) { retval = zend_is_true(&tmp); @@ -1441,7 +1442,7 @@ zend_object *dom_xpath_objects_new(zend_class_entry *class_type) dom_xpath_object *intern = zend_object_alloc(sizeof(dom_xpath_object), class_type); php_dom_xpath_callbacks_ctor(&intern->xpath_callbacks); - intern->register_node_ns = 1; + intern->register_node_ns = true; intern->dom.prop_handler = &dom_xpath_prop_handlers; diff --git a/ext/dom/php_dom.h b/ext/dom/php_dom.h index 1e24b38a64884..891c771d7931c 100644 --- a/ext/dom/php_dom.h +++ b/ext/dom/php_dom.h @@ -66,7 +66,7 @@ extern zend_module_entry dom_module_entry; typedef struct _dom_xpath_object { php_dom_xpath_callbacks xpath_callbacks; - int register_node_ns; + bool register_node_ns; dom_object dom; } dom_xpath_object; diff --git a/ext/pdo/pdo_stmt.c b/ext/pdo/pdo_stmt.c index be5e287111f32..3e4e73d895251 100644 --- a/ext/pdo/pdo_stmt.c +++ b/ext/pdo/pdo_stmt.c @@ -2344,6 +2344,7 @@ static void row_dim_write(zend_object *object, zval *member, zval *value) } } +// todo: make row_prop_exists return bool as well static int row_prop_exists(zend_object *object, zend_string *name, int check_empty, void **cache_slot) { pdo_row_t *row = (pdo_row_t *)object; @@ -2363,11 +2364,14 @@ static int row_prop_exists(zend_object *object, zend_string *name, int check_emp return false; } ZEND_ASSERT(retval == &tmp_val); - int res = check_empty ? i_zend_is_true(retval) : Z_TYPE(tmp_val) != IS_NULL; + bool res = check_empty ? i_zend_is_true(retval) : Z_TYPE(tmp_val) != IS_NULL; zval_ptr_dtor_nogc(retval); + return res; } + +// todo: make row_dim_exists return bool as well static int row_dim_exists(zend_object *object, zval *offset, int check_empty) { if (Z_TYPE_P(offset) == IS_LONG) { @@ -2386,7 +2390,7 @@ static int row_dim_exists(zend_object *object, zval *offset, int check_empty) return false; } ZEND_ASSERT(retval == &tmp_val); - int res = check_empty ? i_zend_is_true(retval) : Z_TYPE(tmp_val) != IS_NULL; + bool res = check_empty ? i_zend_is_true(retval) : Z_TYPE(tmp_val) != IS_NULL; zval_ptr_dtor_nogc(retval); return res; } else { diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c index 20583febe50c5..8f764e1b99d63 100644 --- a/ext/spl/spl_directory.c +++ b/ext/spl/spl_directory.c @@ -851,7 +851,7 @@ PHP_METHOD(DirectoryIterator, seek) } while (intern->u.dir.index < pos) { - bool valid = 0; + bool valid = false; zend_call_method_with_0_params(Z_OBJ_P(ZEND_THIS), Z_OBJCE_P(ZEND_THIS), &intern->u.dir.func_valid, "valid", &retval); valid = zend_is_true(&retval); zval_ptr_dtor(&retval); diff --git a/ext/spl/spl_iterators.c b/ext/spl/spl_iterators.c index 34f7b5e5b02aa..6f7f3c241a75d 100644 --- a/ext/spl/spl_iterators.c +++ b/ext/spl/spl_iterators.c @@ -263,7 +263,6 @@ static void spl_recursive_it_move_forward_ex(spl_recursive_it_object *object, zv zend_class_entry *ce; zval retval, child; zend_object_iterator *sub_iter; - int has_children; SPL_FETCH_SUB_ITERATOR(iterator, object); @@ -308,7 +307,7 @@ static void spl_recursive_it_move_forward_ex(spl_recursive_it_object *object, zv } } if (Z_TYPE(retval) != IS_UNDEF) { - has_children = zend_is_true(&retval); + bool has_children = zend_is_true(&retval); zval_ptr_dtor(&retval); if (has_children) { if (object->max_depth == -1 || object->max_depth > object->level) { diff --git a/ext/spl/spl_observer.c b/ext/spl/spl_observer.c index cc016518917ec..0de3a15a07b8f 100644 --- a/ext/spl/spl_observer.c +++ b/ext/spl/spl_observer.c @@ -440,6 +440,7 @@ PHP_METHOD(SplObjectStorage, attach) spl_object_storage_attach(intern, obj, inf); } /* }}} */ +// todo: make spl_object_storage_has_dimension return bool as well static int spl_object_storage_has_dimension(zend_object *object, zval *offset, int check_empty) { spl_SplObjectStorage *intern = spl_object_storage_from_obj(object); diff --git a/ext/standard/array.c b/ext/standard/array.c index d93ac630c3723..592d25c2115a9 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -6548,7 +6548,7 @@ PHP_FUNCTION(array_filter) fci.params = args; if (zend_call_function(&fci, &fci_cache) == SUCCESS) { - int retval_true; + bool retval_true; zval_ptr_dtor(&args[0]); if (use_type == ARRAY_FILTER_USE_BOTH) { diff --git a/ext/standard/filters.c b/ext/standard/filters.c index 6cb8c5eebb659..452493ba745a1 100644 --- a/ext/standard/filters.c +++ b/ext/standard/filters.c @@ -1113,20 +1113,20 @@ static php_conv_err_t php_conv_get_ulong_prop_ex(const HashTable *ht, zend_ulong } } -static php_conv_err_t php_conv_get_bool_prop_ex(const HashTable *ht, int *pretval, char *field_name, size_t field_name_len) +static php_conv_err_t php_conv_get_bool_prop_ex(const HashTable *ht, bool *pretval, char *field_name, size_t field_name_len) { zval *tmpval = zend_hash_str_find((HashTable *)ht, field_name, field_name_len-1); if (tmpval != NULL) { *pretval = zend_is_true(tmpval); return PHP_CONV_ERR_SUCCESS; } else { - *pretval = 0; + *pretval = false; return PHP_CONV_ERR_NOT_FOUND; } } /* XXX this might need an additional fix so it uses size_t, whereby unsigned is quite big so leaving as is for now */ -static int php_conv_get_uint_prop_ex(const HashTable *ht, unsigned int *pretval, char *field_name, size_t field_name_len) +static php_conv_err_t php_conv_get_uint_prop_ex(const HashTable *ht, unsigned int *pretval, char *field_name, size_t field_name_len) { zend_ulong l; php_conv_err_t err; @@ -1206,8 +1206,8 @@ static php_conv *php_conv_open(int conv_mode, const HashTable *options, int pers int opts = 0; if (options != NULL) { - int opt_binary = 0; - int opt_force_encode_first = 0; + bool opt_binary = false; + bool opt_force_encode_first = false; GET_STR_PROP(options, lbchars, lbchars_len, "line-break-chars", 0); GET_UINT_PROP(options, line_len, "line-length"); diff --git a/ext/standard/http_fopen_wrapper.c b/ext/standard/http_fopen_wrapper.c index 6727311689f9f..0159132cea1fe 100644 --- a/ext/standard/http_fopen_wrapper.c +++ b/ext/standard/http_fopen_wrapper.c @@ -136,7 +136,7 @@ static php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper, zend_string *transport_string; zend_string *errstr = NULL; int have_header = 0; - bool request_fulluri = 0, ignore_errors = 0; + bool request_fulluri = false, ignore_errors = false; struct timeval timeout; char *user_headers = NULL; int header_init = ((flags & HTTP_WRAPPER_HEADER_INIT) != 0); @@ -171,7 +171,7 @@ static php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper, return php_stream_open_wrapper_ex(path, mode, REPORT_ERRORS, NULL, context); } /* Called from a non-http wrapper with http proxying requested (i.e. ftp) */ - request_fulluri = 1; + request_fulluri = true; use_ssl = 0; use_proxy = 1; transport_string = zend_string_copy(Z_STR_P(tmpzval)); @@ -801,7 +801,7 @@ static php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper, /* create filter to decode response body */ if (!(options & STREAM_ONLY_GET_HEADERS)) { - zend_long decode = 1; + bool decode = true; if (context && (tmpzval = php_stream_context_get_option(context, "http", "auto_decode")) != NULL) { decode = zend_is_true(tmpzval); diff --git a/ext/xsl/xsltprocessor.c b/ext/xsl/xsltprocessor.c index 7d0f9b05546d2..7dc040c1d234e 100644 --- a/ext/xsl/xsltprocessor.c +++ b/ext/xsl/xsltprocessor.c @@ -197,7 +197,7 @@ PHP_METHOD(XSLTProcessor, importStylesheet) zval *id, *docp = NULL; xmlDoc *doc = NULL, *newdoc = NULL; xsltStylesheetPtr sheetp; - int clone_docu = 0; + bool clone_docu = false; xmlNode *nodep = NULL; zval *cloneDocu, rv; zend_string *member; @@ -257,7 +257,7 @@ PHP_METHOD(XSLTProcessor, importStylesheet) cloneDocu = zend_std_read_property(Z_OBJ_P(id), member, BP_VAR_R, NULL, &rv); clone_docu = zend_is_true(cloneDocu); zend_string_release_ex(member, 0); - if (clone_docu == 0) { + if (!clone_docu) { /* Check if the stylesheet is using xsl:key, if yes, we have to clone the document _always_ before a transformation. * xsl:key elements may only occur at the top level. Furthermore, all elements at the top level must be in a * namespace (if not, then the stylesheet is not well-formed and this function will have returned false earlier). */ diff --git a/ext/zip/php_zip.c b/ext/zip/php_zip.c index 0c1dfaf5dd131..815ea8b1a46b4 100644 --- a/ext/zip/php_zip.c +++ b/ext/zip/php_zip.c @@ -949,11 +949,12 @@ static zval *php_zip_read_property(zend_object *object, zend_string *name, int t } /* }}} */ +// todo: make php_zip_has_property return bool as well static int php_zip_has_property(zend_object *object, zend_string *name, int type, void **cache_slot) /* {{{ */ { ze_zip_object *obj; zip_prop_handler *hnd = NULL; - int retval = 0; + bool retval = false; obj = php_zip_fetch_object(object); @@ -965,7 +966,7 @@ static int php_zip_has_property(zend_object *object, zend_string *name, int type zval tmp, *prop; if (type == 2) { - retval = 1; + retval = true; } else if ((prop = php_zip_property_reader(obj, hnd, &tmp)) != NULL) { if (type == 1) { retval = zend_is_true(&tmp); diff --git a/sapi/phpdbg/phpdbg.c b/sapi/phpdbg/phpdbg.c index 69db42648047f..0b526d5f27712 100644 --- a/sapi/phpdbg/phpdbg.c +++ b/sapi/phpdbg/phpdbg.c @@ -491,8 +491,8 @@ PHP_FUNCTION(phpdbg_get_executable) { HashTable *options = NULL; zval *option_buffer; - bool by_function = 0; - bool by_opcode = 0; + bool by_function = false; + bool by_opcode = false; HashTable *insert_ht; zend_function *func; @@ -592,8 +592,8 @@ PHP_FUNCTION(phpdbg_end_oplog) HashTable *options = NULL; zval *option_buffer; - bool by_function = 0; - bool by_opcode = 0; + bool by_function = false; + bool by_opcode = false; if (zend_parse_parameters(ZEND_NUM_ARGS(), "|H", &options) == FAILURE) { RETURN_THROWS();