diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index d5702bbb0fb..7ca6a5e6a79 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -1576,7 +1576,7 @@ int ZEND_FASTCALL zendlex(zend_parser_stack_elem *elem) /* {{{ */ ZEND_API void zend_initialize_class_data(zend_class_entry *ce, zend_bool nullify_handlers) /* {{{ */ { - zend_bool persistent_hashes = (ce->type == ZEND_INTERNAL_CLASS) ? 1 : 0; + zend_bool persistent_hashes = ce->type == ZEND_INTERNAL_CLASS; ce->refcount = 1; ce->ce_flags = ZEND_ACC_CONSTANTS_UPDATED; diff --git a/Zend/zend_constants.c b/Zend/zend_constants.c index 80ed43513af..8fd1021c846 100644 --- a/Zend/zend_constants.c +++ b/Zend/zend_constants.c @@ -83,9 +83,9 @@ static int clean_module_constant(zval *el, void *arg) int module_number = *(int *)arg; if (ZEND_CONSTANT_MODULE_NUMBER(c) == module_number) { - return 1; + return ZEND_HASH_APPLY_REMOVE; } else { - return 0; + return ZEND_HASH_APPLY_KEEP; } } diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index 2e0a14d19f2..dd3ddbc9308 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -845,10 +845,7 @@ static zend_bool zend_verify_weak_scalar_type_hint(zend_uchar type_hint, zval *a zend_string *dest; /* on success "arg" is converted to IS_STRING */ - if (!zend_parse_arg_str_weak(arg, &dest)) { - return 0; - } - return 1; + return zend_parse_arg_str_weak(arg, &dest); } default: return 0; diff --git a/Zend/zend_ini.c b/Zend/zend_ini.c index b8185950ae2..e3d61dea8c3 100644 --- a/Zend/zend_ini.c +++ b/Zend/zend_ini.c @@ -36,11 +36,8 @@ static int zend_remove_ini_entries(zval *el, void *arg) /* {{{ */ { zend_ini_entry *ini_entry = (zend_ini_entry *)Z_PTR_P(el); int module_number = *(int *)arg; - if (ini_entry->module_number == module_number) { - return 1; - } else { - return 0; - } + + return ini_entry->module_number == module_number; } /* }}} */ diff --git a/Zend/zend_list.c b/Zend/zend_list.c index aa16c5b7efc..cf878ef4302 100644 --- a/Zend/zend_list.c +++ b/Zend/zend_list.c @@ -245,11 +245,8 @@ void zend_destroy_rsrc_list(HashTable *ht) static int clean_module_resource(zval *zv, void *arg) { int resource_id = *(int *)arg; - if (Z_RES_TYPE_P(zv) == resource_id) { - return 1; - } else { - return 0; - } + + return Z_RES_TYPE_P(zv) == resource_id; } diff --git a/Zend/zend_stream.c b/Zend/zend_stream.c index 22726f08128..84af16321bd 100644 --- a/Zend/zend_stream.c +++ b/Zend/zend_stream.c @@ -186,7 +186,7 @@ ZEND_API int zend_stream_fixup(zend_file_handle *file_handle, char **buf, size_t return FAILURE; } memset(&file_handle->handle.stream.mmap, 0, sizeof(zend_mmap)); - file_handle->handle.stream.isatty = isatty(fileno((FILE *)file_handle->handle.stream.handle)) ? 1 : 0; + file_handle->handle.stream.isatty = isatty(fileno((FILE *)file_handle->handle.stream.handle)); file_handle->handle.stream.reader = (zend_stream_reader_t)zend_stream_stdio_reader; file_handle->handle.stream.closer = (zend_stream_closer_t)zend_stream_stdio_closer; file_handle->handle.stream.fsizer = (zend_stream_fsizer_t)zend_stream_stdio_fsizer; diff --git a/Zend/zend_virtual_cwd.c b/Zend/zend_virtual_cwd.c index 8a90f25bf7f..050906c86ec 100644 --- a/Zend/zend_virtual_cwd.c +++ b/Zend/zend_virtual_cwd.c @@ -665,7 +665,7 @@ static size_t tsrm_realpath_r(char *path, size_t start, size_t len, int *ll, tim if(pbuffer->ReparseTag == IO_REPARSE_TAG_SYMLINK) { reparsetarget = pbuffer->SymbolicLinkReparseBuffer.ReparseTarget; - isabsolute = (pbuffer->SymbolicLinkReparseBuffer.Flags == 0) ? 1 : 0; + isabsolute = pbuffer->SymbolicLinkReparseBuffer.Flags == 0; #if VIRTUAL_CWD_DEBUG printname = php_win32_ioutil_w_to_any(reparsetarget + pbuffer->MountPointReparseBuffer.PrintNameOffset / sizeof(WCHAR)); if (!printname) { diff --git a/ext/bcmath/libbcmath/src/num2str.c b/ext/bcmath/libbcmath/src/num2str.c index 742d3278e73..93026815be5 100644 --- a/ext/bcmath/libbcmath/src/num2str.c +++ b/ext/bcmath/libbcmath/src/num2str.c @@ -50,7 +50,7 @@ zend_string int index, signch; /* Allocate the string memory. */ - signch = ( num->n_sign == PLUS ? 0 : 1 ); /* Number of sign chars. */ + signch = num->n_sign != PLUS; /* Number of sign chars. */ if (scale > 0) str = zend_string_alloc(num->n_len + scale + signch + 1, 0); else diff --git a/ext/curl/multi.c b/ext/curl/multi.c index b65ca891327..cacda1aef44 100644 --- a/ext/curl/multi.c +++ b/ext/curl/multi.c @@ -595,11 +595,8 @@ static int _php_curl_multi_setopt(php_curlm *mh, zend_long option, zval *zvalue, } SAVE_CURLM_ERROR(mh, error); - if (error != CURLM_OK) { - return 1; - } else { - return 0; - } + + return error != CURLM_OK; } /* }}} */ diff --git a/ext/curl/share.c b/ext/curl/share.c index 772f899ff69..6c954f7d325 100644 --- a/ext/curl/share.c +++ b/ext/curl/share.c @@ -86,11 +86,8 @@ static int _php_curl_share_setopt(php_curlsh *sh, zend_long option, zval *zvalue } SAVE_CURLSH_ERROR(sh, error); - if (error != CURLSHE_OK) { - return 1; - } else { - return 0; - } + + return error != CURLSHE_OK; } /* }}} */ diff --git a/ext/filter/tests/030.phpt b/ext/filter/tests/030.phpt index 6c380dee901..c8e7d4b6ef1 100644 --- a/ext/filter/tests/030.phpt +++ b/ext/filter/tests/030.phpt @@ -51,7 +51,7 @@ $ipv6_test = array( ); foreach ($ipv6_test as $ip => $exp) { $out = filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6); - $out = (int) ($out === false ? 0 : 1); + $out = $out !== false; if ($exp != $out) { echo "$ip failed (expected ", $exp?"true":"false", ", got ", $out?"true":"false", ")\n"; diff --git a/ext/imap/php_imap.c b/ext/imap/php_imap.c index 9e626a4cfa3..28636578276 100644 --- a/ext/imap/php_imap.c +++ b/ext/imap/php_imap.c @@ -4074,11 +4074,8 @@ int _php_imap_mail(char *to, char *subject, char *message, char *headers, char * } fprintf(sendmail, "\n%s\n", message); ret = pclose(sendmail); - if (ret == -1) { - return 0; - } else { - return 1; - } + + return ret != -1; } else { php_error_docref(NULL, E_WARNING, "Could not execute mail delivery program"); return 0; diff --git a/ext/interbase/interbase.c b/ext/interbase/interbase.c index 478133296ba..291bb15e282 100644 --- a/ext/interbase/interbase.c +++ b/ext/interbase/interbase.c @@ -869,7 +869,7 @@ int _php_ibase_attach_db(char **args, size_t *len, zend_long *largs, isc_db_hand buf_len -= dpb_len; } if (largs[SYNC] && buf_len > 0) { - dpb_len = slprintf(dpb, buf_len, "%c\1%c", isc_dpb_force_write, largs[SYNC] == isc_spb_prp_wm_sync ? 1 : 0); + dpb_len = slprintf(dpb, buf_len, "%c\1%c", isc_dpb_force_write, largs[SYNC] == isc_spb_prp_wm_sync); dpb += dpb_len; buf_len -= dpb_len; } diff --git a/ext/intl/dateformat/dateformat_parse.c b/ext/intl/dateformat/dateformat_parse.c index a04ef1105ec..af960952423 100644 --- a/ext/intl/dateformat/dateformat_parse.c +++ b/ext/intl/dateformat/dateformat_parse.c @@ -116,7 +116,7 @@ static void internal_parse_to_localtime(IntlDateFormatter_object *dfo, char* tex /* Is in DST? */ isInDST = ucal_inDaylightTime(parsed_calendar , &INTL_DATA_ERROR_CODE(dfo)); INTL_METHOD_CHECK_STATUS( dfo, "Date parsing - localtime failed : while checking if currently in DST." ); - add_assoc_long( return_value, CALENDAR_ISDST,(isInDST==1?1:0)); + add_assoc_long( return_value, CALENDAR_ISDST,isInDST==1); } /* }}} */ diff --git a/ext/mysqlnd/mysqlnd_connection.c b/ext/mysqlnd/mysqlnd_connection.c index 8745cc4edc8..a361361818a 100644 --- a/ext/mysqlnd/mysqlnd_connection.c +++ b/ext/mysqlnd/mysqlnd_connection.c @@ -1578,7 +1578,7 @@ MYSQLND_METHOD(mysqlnd_conn_data, change_user)(MYSQLND_CONN_DATA * const conn, DBG_ENTER("mysqlnd_conn_data::change_user"); DBG_INF_FMT("conn=%llu user=%s passwd=%s db=%s silent=%u", - conn->thread_id, user?user:"", passwd?"***":"null", db?db:"", (silent == TRUE)?1:0 ); + conn->thread_id, user?user:"", passwd?"***":"null", db?db:"", silent == TRUE); if (PASS != conn->m->local_tx_start(conn, this_func)) { goto end; diff --git a/ext/pdo/pdo_stmt.c b/ext/pdo/pdo_stmt.c index bf41102afc6..37cca8a0555 100644 --- a/ext/pdo/pdo_stmt.c +++ b/ext/pdo/pdo_stmt.c @@ -2004,7 +2004,7 @@ static PHP_METHOD(PDOStatement, setFetchMode) RETVAL_BOOL( pdo_stmt_setup_fetch_mode(INTERNAL_FUNCTION_PARAM_PASSTHRU, - stmt, 0) == SUCCESS ? 1 : 0 + stmt, 0) == SUCCESS ); } /* }}} */ diff --git a/ext/pdo_mysql/mysql_driver.c b/ext/pdo_mysql/mysql_driver.c index 2cec3daa422..3ff03e54b3e 100644 --- a/ext/pdo_mysql/mysql_driver.c +++ b/ext/pdo_mysql/mysql_driver.c @@ -388,7 +388,7 @@ static int pdo_mysql_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val) PDO_DBG_RETURN(1); case PDO_ATTR_DEFAULT_STR_PARAM: - ((pdo_mysql_db_handle *)dbh->driver_data)->assume_national_character_set_strings = lval == PDO_PARAM_STR_NATL ? 1 : 0; + ((pdo_mysql_db_handle *)dbh->driver_data)->assume_national_character_set_strings = lval == PDO_PARAM_STR_NATL; PDO_DBG_RETURN(1); case PDO_MYSQL_ATTR_USE_BUFFERED_QUERY: @@ -617,7 +617,7 @@ static int pdo_mysql_handle_factory(pdo_dbh_t *dbh, zval *driver_options) PDO_ATTR_EMULATE_PREPARES, H->emulate_prepare); H->assume_national_character_set_strings = pdo_attr_lval(driver_options, - PDO_ATTR_DEFAULT_STR_PARAM, 0) == PDO_PARAM_STR_NATL ? 1 : 0; + PDO_ATTR_DEFAULT_STR_PARAM, 0) == PDO_PARAM_STR_NATL; #ifndef PDO_USE_MYSQLND H->max_buffer_size = pdo_attr_lval(driver_options, PDO_MYSQL_ATTR_MAX_BUFFER_SIZE, H->max_buffer_size); diff --git a/ext/pdo_pgsql/pgsql_statement.c b/ext/pdo_pgsql/pgsql_statement.c index 86cb084a1d8..c27d4f6baa6 100644 --- a/ext/pdo_pgsql/pgsql_statement.c +++ b/ext/pdo_pgsql/pgsql_statement.c @@ -553,7 +553,7 @@ static int pgsql_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr, zend_ulon break; case PDO_PARAM_BOOL: - S->cols[colno].boolval = **ptr == 't' ? 1: 0; + S->cols[colno].boolval = **ptr == 't'; *ptr = (char *) &(S->cols[colno].boolval); *len = sizeof(zend_bool); break; diff --git a/ext/phar/phar_object.c b/ext/phar/phar_object.c index 74910b25844..7538c49b3cb 100644 --- a/ext/phar/phar_object.c +++ b/ext/phar/phar_object.c @@ -3618,7 +3618,7 @@ static void phar_add_file(phar_archive_data **pphar, char *filename, size_t file php_stream_statbuf ssb; if (filename_len >= sizeof(".phar")-1) { - start_pos = ('/' == filename[0] ? 1 : 0); /* account for any leading slash: multiple-leads handled elsewhere */ + start_pos = '/' == filename[0]; /* account for any leading slash: multiple-leads handled elsewhere */ if (!memcmp(&filename[start_pos], ".phar", sizeof(".phar")-1) && (filename[start_pos+5] == '/' || filename[start_pos+5] == '\\' || filename[start_pos+5] == '\0')) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Cannot create any files in magic \".phar\" directory"); return; diff --git a/ext/spl/spl_heap.c b/ext/spl/spl_heap.c index 0993cd4b5ee..e3e0b4817ba 100644 --- a/ext/spl/spl_heap.c +++ b/ext/spl/spl_heap.c @@ -178,7 +178,7 @@ static int spl_ptr_heap_zval_max_cmp(zval *a, zval *b, zval *object) { /* {{{ */ /* exception or call failure */ return 0; } - return lval > 0 ? 1 : (lval < 0 ? -1 : 0); + return ZEND_NORMALIZE_BOOL(lval); } } @@ -202,7 +202,7 @@ static int spl_ptr_heap_zval_min_cmp(zval *a, zval *b, zval *object) { /* {{{ */ /* exception or call failure */ return 0; } - return lval > 0 ? 1 : (lval < 0 ? -1 : 0); + return ZEND_NORMALIZE_BOOL(lval); } } @@ -230,7 +230,7 @@ static int spl_ptr_pqueue_elem_cmp(zval *a_zv, zval *b_zv, zval *object) { /* {{ /* exception or call failure */ return 0; } - return lval > 0 ? 1 : (lval < 0 ? -1 : 0); + return ZEND_NORMALIZE_BOOL(lval); } } diff --git a/ext/spl/spl_observer.c b/ext/spl/spl_observer.c index 60faf2ce9e4..4e244d0945d 100644 --- a/ext/spl/spl_observer.c +++ b/ext/spl/spl_observer.c @@ -352,7 +352,7 @@ static int spl_object_storage_compare_info(zval *e1, zval *e2) /* {{{ */ return 1; } - return Z_LVAL(result) > 0 ? 1 : (Z_LVAL(result) < 0 ? -1 : 0); + return ZEND_NORMALIZE_BOOL(Z_LVAL(result)); } /* }}} */ diff --git a/ext/standard/array.c b/ext/standard/array.c index 3d1b59aa64c..a6dda1ce183 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -170,7 +170,7 @@ static int php_array_key_compare(const void *a, const void *b) /* {{{ */ } } } - return l1 > l2 ? 1 : (l1 < l2 ? -1 : 0); + return ZEND_NORMALIZE_BOOL(l1 > l2); } /* }}} */ @@ -978,7 +978,7 @@ static int php_array_user_compare(const void *a, const void *b) /* {{{ */ zval_ptr_dtor(&retval); zval_ptr_dtor(&args[1]); zval_ptr_dtor(&args[0]); - return ret < 0 ? -1 : ret > 0 ? 1 : 0; + return ZEND_NORMALIZE_BOOL(ret); } else { zval_ptr_dtor(&args[1]); zval_ptr_dtor(&args[0]); @@ -1101,7 +1101,7 @@ static int php_array_user_key_compare(const void *a, const void *b) /* {{{ */ zval_ptr_dtor(&args[0]); zval_ptr_dtor(&args[1]); - return result < 0 ? -1 : result > 0 ? 1 : 0; + return ZEND_NORMALIZE_BOOL(result); } /* }}} */ @@ -4583,7 +4583,7 @@ static int zval_user_compare(zval *a, zval *b) /* {{{ */ if (zend_call_function(&BG(user_compare_fci), &BG(user_compare_fci_cache)) == SUCCESS && Z_TYPE(retval) != IS_UNDEF) { zend_long ret = zval_get_long(&retval); zval_ptr_dtor(&retval); - return ret < 0 ? -1 : ret > 0 ? 1 : 0; + return ZEND_NORMALIZE_BOOL(ret); } else { return 0; } diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 9aeb2fb3a9d..f3905832a06 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -4340,7 +4340,7 @@ static int parse_opts(char * opts, opt_struct ** result) (*opts >= 97 && *opts <= 122) /* a - z */ ) { paras->opt_char = *opts; - paras->need_param = (*(++opts) == ':') ? 1 : 0; + paras->need_param = *(++opts) == ':'; paras->opt_name = NULL; if (paras->need_param == 1) { opts++; diff --git a/ext/standard/versioning.c b/ext/standard/versioning.c index 27d96f0163b..59979290b40 100644 --- a/ext/standard/versioning.c +++ b/ext/standard/versioning.c @@ -24,8 +24,6 @@ #include "php.h" #include "php_versioning.h" -#define sign(n) ((n)<0?-1:((n)>0?1:0)) - /* {{{ php_canonicalize_version() */ PHPAPI char * @@ -115,7 +113,7 @@ compare_special_version_forms(char *form1, char *form2) break; } } - return sign(found1 - found2); + return ZEND_NORMALIZE_BOOL(found1 - found2); } /* }}} */ @@ -160,7 +158,7 @@ php_version_compare(const char *orig_ver1, const char *orig_ver2) /* compare element numerically */ l1 = strtol(p1, NULL, 10); l2 = strtol(p2, NULL, 10); - compare = sign(l1 - l2); + compare = ZEND_NORMALIZE_BOOL(l1 - l2); } else if (!isdigit(*p1) && !isdigit(*p2)) { /* compare element names */ compare = compare_special_version_forms(p1, p2); diff --git a/main/rfc1867.c b/main/rfc1867.c index 8a8e335ef43..e1167ebf509 100644 --- a/main/rfc1867.c +++ b/main/rfc1867.c @@ -281,11 +281,7 @@ static int fill_buffer(multipart_buffer *self) /* eof if we are out of bytes, or if we hit the final boundary */ static int multipart_buffer_eof(multipart_buffer *self) { - if ( (self->bytes_in_buffer == 0 && fill_buffer(self) < 1) ) { - return 1; - } else { - return 0; - } + return self->bytes_in_buffer == 0 && fill_buffer(self) < 1; } /* create new multipart_buffer structure */ diff --git a/main/streams/mmap.c b/main/streams/mmap.c index 94c80a9dc52..8e8140f1480 100644 --- a/main/streams/mmap.c +++ b/main/streams/mmap.c @@ -46,7 +46,7 @@ PHPAPI char *_php_stream_mmap_range(php_stream *stream, size_t offset, size_t le PHPAPI int _php_stream_mmap_unmap(php_stream *stream) { - return php_stream_set_option(stream, PHP_STREAM_OPTION_MMAP_API, PHP_STREAM_MMAP_UNMAP, NULL) == PHP_STREAM_OPTION_RETURN_OK ? 1 : 0; + return php_stream_set_option(stream, PHP_STREAM_OPTION_MMAP_API, PHP_STREAM_MMAP_UNMAP, NULL) == PHP_STREAM_OPTION_RETURN_OK; } PHPAPI int _php_stream_mmap_unmap_ex(php_stream *stream, zend_off_t readden)