From b6c2a1ac63def8cc5cc913bd0b08ad98abf9ff27 Mon Sep 17 00:00:00 2001 From: Andreas Leathley Date: Mon, 16 May 2022 15:03:57 +0200 Subject: [PATCH 01/10] Deprecation on implicit bool conversions to true for values other than 1 --- .../explicit_casts_should_not_warn.phpt | 28 +++++++++++++ .../no_warning_compatible_float.phpt | 38 ++++++++++++++++++ .../no_warning_compatible_int.phpt | 38 ++++++++++++++++++ .../no_warning_compatible_string.phpt | 38 ++++++++++++++++++ .../warnings_float_non_zero_or_one.phpt | 40 +++++++++++++++++++ .../warnings_int_non_zero_or_one.phpt | 40 +++++++++++++++++++ .../warnings_string_non_zero_or_one.phpt | 40 +++++++++++++++++++ .../tests/type_declarations/scalar_basic.phpt | 5 +++ .../scalar_return_basic.phpt | 5 +++ .../scalar_return_basic_64bit.phpt | 5 +++ .../union_types/type_checking_weak.phpt | 24 +++++------ Zend/zend_API.c | 16 ++++++++ Zend/zend_operators.c | 13 ++++++ Zend/zend_operators.h | 33 +++++++++++++++ .../tests/misc/get_browser_error.phpt | 2 + ext/standard/tests/strings/strstr.phpt | 2 + .../tests/strings/substr_compare.phpt | 2 +- 17 files changed, 356 insertions(+), 13 deletions(-) create mode 100644 Zend/tests/scalar_to_bool/explicit_casts_should_not_warn.phpt create mode 100644 Zend/tests/scalar_to_bool/no_warning_compatible_float.phpt create mode 100644 Zend/tests/scalar_to_bool/no_warning_compatible_int.phpt create mode 100644 Zend/tests/scalar_to_bool/no_warning_compatible_string.phpt create mode 100644 Zend/tests/scalar_to_bool/warnings_float_non_zero_or_one.phpt create mode 100644 Zend/tests/scalar_to_bool/warnings_int_non_zero_or_one.phpt create mode 100644 Zend/tests/scalar_to_bool/warnings_string_non_zero_or_one.phpt diff --git a/Zend/tests/scalar_to_bool/explicit_casts_should_not_warn.phpt b/Zend/tests/scalar_to_bool/explicit_casts_should_not_warn.phpt new file mode 100644 index 0000000000000..65cbaf5637044 --- /dev/null +++ b/Zend/tests/scalar_to_bool/explicit_casts_should_not_warn.phpt @@ -0,0 +1,28 @@ +--TEST-- +Explicit (bool) cast must not warn +--FILE-- + +--EXPECT-- +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) +bool(true) diff --git a/Zend/tests/scalar_to_bool/no_warning_compatible_float.phpt b/Zend/tests/scalar_to_bool/no_warning_compatible_float.phpt new file mode 100644 index 0000000000000..1eb64eca6751e --- /dev/null +++ b/Zend/tests/scalar_to_bool/no_warning_compatible_float.phpt @@ -0,0 +1,38 @@ +--TEST-- +Compatible float to bool conversions with values 0 or 1 +--FILE-- +a = -0.0; +var_dump($instance->a); + +?> +--EXPECTF-- +Function calls: +bool(true) +bool(false) +bool(false) +Function returns: +bool(false) +Typed property assignment: +bool(false) diff --git a/Zend/tests/scalar_to_bool/no_warning_compatible_int.phpt b/Zend/tests/scalar_to_bool/no_warning_compatible_int.phpt new file mode 100644 index 0000000000000..82d4339aeaa39 --- /dev/null +++ b/Zend/tests/scalar_to_bool/no_warning_compatible_int.phpt @@ -0,0 +1,38 @@ +--TEST-- +Compatible int to bool conversions with values 0 or 1 +--FILE-- +a = 1; +var_dump($instance->a); + +?> +--EXPECTF-- +Function calls: +bool(true) +bool(false) +bool(false) +Function returns: +bool(false) +Typed property assignment: +bool(true) diff --git a/Zend/tests/scalar_to_bool/no_warning_compatible_string.phpt b/Zend/tests/scalar_to_bool/no_warning_compatible_string.phpt new file mode 100644 index 0000000000000..d4356d2899f56 --- /dev/null +++ b/Zend/tests/scalar_to_bool/no_warning_compatible_string.phpt @@ -0,0 +1,38 @@ +--TEST-- +Compatible string to bool conversions with values "", "0" or "1" +--FILE-- +a = "1"; +var_dump($instance->a); + +?> +--EXPECTF-- +Function calls: +bool(false) +bool(true) +bool(false) +Function returns: +bool(false) +Typed property assignment: +bool(true) diff --git a/Zend/tests/scalar_to_bool/warnings_float_non_zero_or_one.phpt b/Zend/tests/scalar_to_bool/warnings_float_non_zero_or_one.phpt new file mode 100644 index 0000000000000..85495ed171b3d --- /dev/null +++ b/Zend/tests/scalar_to_bool/warnings_float_non_zero_or_one.phpt @@ -0,0 +1,40 @@ +--TEST-- +Implicit float to bool conversions with values other than 0 or 1 should warn for variables +--FILE-- +a = 13.0; +var_dump($instance->a); + +?> +--EXPECTF-- +Function calls: + +Deprecated: Implicit conversion from float 1.1 to true, only 0 or 1 are allowed in %s on line %d +bool(true) +Function returns: + +Deprecated: Implicit conversion from float -0.3 to true, only 0 or 1 are allowed in %s on line %d +bool(true) +Typed property assignment: + +Deprecated: Implicit conversion from float 13 to true, only 0 or 1 are allowed in %s on line %d +bool(true) diff --git a/Zend/tests/scalar_to_bool/warnings_int_non_zero_or_one.phpt b/Zend/tests/scalar_to_bool/warnings_int_non_zero_or_one.phpt new file mode 100644 index 0000000000000..e187a473917ec --- /dev/null +++ b/Zend/tests/scalar_to_bool/warnings_int_non_zero_or_one.phpt @@ -0,0 +1,40 @@ +--TEST-- +Implicit int to bool conversions with values other than 0 or 1 should warn for variables +--FILE-- +a = 13; +var_dump($instance->a); + +?> +--EXPECTF-- +Function calls: + +Deprecated: Implicit conversion from integer 5 to true, only 0 or 1 are allowed in %s on line %d +bool(true) +Function returns: + +Deprecated: Implicit conversion from integer 3 to true, only 0 or 1 are allowed in %s on line %d +bool(true) +Typed property assignment: + +Deprecated: Implicit conversion from integer 13 to true, only 0 or 1 are allowed in %s on line %d +bool(true) diff --git a/Zend/tests/scalar_to_bool/warnings_string_non_zero_or_one.phpt b/Zend/tests/scalar_to_bool/warnings_string_non_zero_or_one.phpt new file mode 100644 index 0000000000000..edb2d94690be3 --- /dev/null +++ b/Zend/tests/scalar_to_bool/warnings_string_non_zero_or_one.phpt @@ -0,0 +1,40 @@ +--TEST-- +Implicit string to bool conversions with values other than empty string, "0" or "1" should warn for variables +--FILE-- +a = "0.0"; +var_dump($instance->a); + +?> +--EXPECTF-- +Function calls: + +Deprecated: Implicit conversion from string "on" to true, only "", "0" or "1" are allowed in %s on line %d +bool(true) +Function returns: + +Deprecated: Implicit conversion from string "inactive" to true, only "", "0" or "1" are allowed in %s on line %d +bool(true) +Typed property assignment: + +Deprecated: Implicit conversion from string "0.0" to true, only "", "0" or "1" are allowed in %s on line %d +bool(true) diff --git a/Zend/tests/type_declarations/scalar_basic.phpt b/Zend/tests/type_declarations/scalar_basic.phpt index c69d17c8c7004..ab1da10480f9d 100644 --- a/Zend/tests/type_declarations/scalar_basic.phpt +++ b/Zend/tests/type_declarations/scalar_basic.phpt @@ -232,21 +232,26 @@ bool(true) bool(true) *** Trying float(1.5) +E_DEPRECATED: Implicit conversion from float 1.5 to true, only 0 or 1 are allowed on line %d bool(true) *** Trying string(2) "1a" +E_DEPRECATED: Implicit conversion from string "1a" to true, only "", "0" or "1" are allowed on line %d bool(true) *** Trying string(1) "a" +E_DEPRECATED: Implicit conversion from string "a" to true, only "", "0" or "1" are allowed on line %d bool(true) *** Trying string(0) "" bool(false) *** Trying int(%d) +E_DEPRECATED: Implicit conversion from integer 9223372036854775807 to true, only 0 or 1 are allowed on line %d bool(true) *** Trying float(NAN) +E_DEPRECATED: Implicit conversion from float NAN to true, only 0 or 1 are allowed on line %d bool(true) *** Trying bool(true) diff --git a/Zend/tests/type_declarations/scalar_return_basic.phpt b/Zend/tests/type_declarations/scalar_return_basic.phpt index 0cdce348c580c..9ab98a83e1cf1 100644 --- a/Zend/tests/type_declarations/scalar_return_basic.phpt +++ b/Zend/tests/type_declarations/scalar_return_basic.phpt @@ -183,16 +183,21 @@ bool(true) *** Trying float(1) bool(true) *** Trying float(1.5) +E_DEPRECATED: Implicit conversion from float 1.5 to true, only 0 or 1 are allowed on line %d bool(true) *** Trying string(2) "1a" +E_DEPRECATED: Implicit conversion from string "1a" to true, only "", "0" or "1" are allowed on line %d bool(true) *** Trying string(1) "a" +E_DEPRECATED: Implicit conversion from string "a" to true, only "", "0" or "1" are allowed on line %d bool(true) *** Trying string(0) "" bool(false) *** Trying int(2147483647) +E_DEPRECATED: Implicit conversion from integer -1 to true, only 0 or 1 are allowed on line %d bool(true) *** Trying float(NAN) +E_DEPRECATED: Implicit conversion from float NAN to true, only 0 or 1 are allowed on line %d bool(true) *** Trying bool(true) bool(true) diff --git a/Zend/tests/type_declarations/scalar_return_basic_64bit.phpt b/Zend/tests/type_declarations/scalar_return_basic_64bit.phpt index 644ff58299440..fb4b6f14dc6c7 100644 --- a/Zend/tests/type_declarations/scalar_return_basic_64bit.phpt +++ b/Zend/tests/type_declarations/scalar_return_basic_64bit.phpt @@ -183,16 +183,21 @@ bool(true) *** Trying float(1) bool(true) *** Trying float(1.5) +E_DEPRECATED: Implicit conversion from float 1.5 to true, only 0 or 1 are allowed on line %d bool(true) *** Trying string(2) "1a" +E_DEPRECATED: Implicit conversion from string "1a" to true, only "", "0" or "1" are allowed on line %d bool(true) *** Trying string(1) "a" +E_DEPRECATED: Implicit conversion from string "a" to true, only "", "0" or "1" are allowed on line %d bool(true) *** Trying string(0) "" bool(false) *** Trying int(9223372036854775807) +E_DEPRECATED: Implicit conversion from integer 9223372036854775807 to true, only 0 or 1 are allowed on line %d bool(true) *** Trying float(NAN) +E_DEPRECATED: Implicit conversion from float NAN to true, only 0 or 1 are allowed on line %d bool(true) *** Trying bool(true) bool(true) diff --git a/Zend/tests/type_declarations/union_types/type_checking_weak.phpt b/Zend/tests/type_declarations/union_types/type_checking_weak.phpt index 351a3e9e78ede..6f2c5e1be65fb 100644 --- a/Zend/tests/type_declarations/union_types/type_checking_weak.phpt +++ b/Zend/tests/type_declarations/union_types/type_checking_weak.phpt @@ -98,8 +98,8 @@ Type int|float|bool: INF => INF "42" => 42 "42.0" => 42.0 -"42x" => true -"x" => true +"42x" => true (Implicit conversion from string "42x" to true, only "", "0" or "1" are allowed) +"x" => true (Implicit conversion from string "x" to true, only "", "0" or "1" are allowed) "" => false true => true false => false @@ -111,11 +111,11 @@ new WithToString => Argument ... must be of type int|float|bool, WithToString gi Type int|bool: 42 => 42 42.0 => 42 -INF => true +INF => true (Implicit conversion from float INF to true, only 0 or 1 are allowed) "42" => 42 "42.0" => 42 -"42x" => true -"x" => true +"42x" => true (Implicit conversion from string "42x" to true, only "", "0" or "1" are allowed) +"x" => true (Implicit conversion from string "x" to true, only "", "0" or "1" are allowed) "" => false true => true false => false @@ -189,13 +189,13 @@ new stdClass => Argument ... must be of type array|string, stdClass given new WithToString => "__toString()" Type bool|array: -42 => true -42.0 => true -INF => true -"42" => true -"42.0" => true -"42x" => true -"x" => true +42 => true (Implicit conversion from integer 42 to true, only 0 or 1 are allowed) +42.0 => true (Implicit conversion from float 42 to true, only 0 or 1 are allowed) +INF => true (Implicit conversion from float INF to true, only 0 or 1 are allowed) +"42" => true (Implicit conversion from string "42" to true, only "", "0" or "1" are allowed) +"42.0" => true (Implicit conversion from string "42.0" to true, only "", "0" or "1" are allowed) +"42x" => true (Implicit conversion from string "42x" to true, only "", "0" or "1" are allowed) +"x" => true (Implicit conversion from string "x" to true, only "", "0" or "1" are allowed) "" => false true => true false => false diff --git a/Zend/zend_API.c b/Zend/zend_API.c index bfcbe2e5f3e17..ddc98a1586e28 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -473,6 +473,22 @@ ZEND_API bool ZEND_FASTCALL zend_parse_arg_bool_weak(zval *arg, bool *dest, uint if (UNEXPECTED(Z_TYPE_P(arg) == IS_NULL) && !zend_null_arg_deprecated("bool", arg_num)) { return 0; } + if (UNEXPECTED(!zend_scalar_is_valid_bool(arg))) { + /* Check arg_num is not (uint32_t)-1, as otherwise its called by + * zend_verify_weak_scalar_type_hint_no_sideeffect() */ + if (arg_num != (uint32_t)-1) { + if (Z_TYPE_P(arg) == IS_DOUBLE) { + zend_incompatible_double_to_bool_error(Z_DVAL_P(arg)); + } else if (Z_TYPE_P(arg) == IS_LONG) { + zend_incompatible_long_to_bool_error(Z_LVAL_P(arg)); + } else if (Z_TYPE_P(arg) == IS_STRING) { + zend_incompatible_string_to_bool_error(Z_STR_P(arg)); + } + } + if (UNEXPECTED(EG(exception))) { + return 0; + } + } *dest = zend_is_true(arg); } else { return 0; diff --git a/Zend/zend_operators.c b/Zend/zend_operators.c index 8a0cc8131be44..3738bf4dc53d7 100644 --- a/Zend/zend_operators.c +++ b/Zend/zend_operators.c @@ -836,6 +836,19 @@ ZEND_API void ZEND_COLD zend_incompatible_string_to_long_error(const zend_string zend_error(E_DEPRECATED, "Implicit conversion from float-string \"%s\" to int loses precision", ZSTR_VAL(s)); } +ZEND_API void ZEND_COLD zend_incompatible_double_to_bool_error(double d) +{ + zend_error_unchecked(E_DEPRECATED, "Implicit conversion from float %.*H to true, only 0 or 1 are allowed", -1, d); +} +ZEND_API void ZEND_COLD zend_incompatible_long_to_bool_error(const zend_long l) +{ + zend_error(E_DEPRECATED, "Implicit conversion from integer %ld to true, only 0 or 1 are allowed", l); +} +ZEND_API void ZEND_COLD zend_incompatible_string_to_bool_error(const zend_string *s) +{ + zend_error(E_DEPRECATED, "Implicit conversion from string \"%s\" to true, only \"\", \"0\" or \"1\" are allowed", ZSTR_VAL(s)); +} + ZEND_API zend_long ZEND_FASTCALL zval_get_long_func(zval *op, bool is_strict) /* {{{ */ { try_again: diff --git a/Zend/zend_operators.h b/Zend/zend_operators.h index 346706d22beae..cab179911c24e 100644 --- a/Zend/zend_operators.h +++ b/Zend/zend_operators.h @@ -138,9 +138,42 @@ static zend_always_inline bool zend_is_long_compatible(double d, zend_long l) { return (double)l == d; } +static zend_always_inline bool zend_scalar_is_valid_bool(zval *arg) { + bool result = 0; + + switch (Z_TYPE_P(arg)) { + case IS_TRUE: + case IS_FALSE: + result = 1; + break; + case IS_LONG: + if (Z_LVAL_P(arg) == 0 || Z_LVAL_P(arg) == 1) { + result = 1; + } + break; + case IS_DOUBLE: + if (Z_DVAL_P(arg) == 0.0 || Z_DVAL_P(arg) == 1.0) { + result = 1; + } + break; + case IS_STRING: + if (Z_STRLEN_P(arg) == 0 || (Z_STRLEN_P(arg) == 1 && (Z_STRVAL_P(arg)[0] == '0' || Z_STRVAL_P(arg)[0] == '1'))) { + result = 1; + } + break; + default: + break; + } + return result; +} + ZEND_API void zend_incompatible_double_to_long_error(double d); ZEND_API void zend_incompatible_string_to_long_error(const zend_string *s); +ZEND_API void zend_incompatible_double_to_bool_error(double d); +ZEND_API void zend_incompatible_long_to_bool_error(const zend_long l); +ZEND_API void zend_incompatible_string_to_bool_error(const zend_string *s); + static zend_always_inline zend_long zend_dval_to_lval_safe(double d) { zend_long l = zend_dval_to_lval(d); diff --git a/ext/standard/tests/misc/get_browser_error.phpt b/ext/standard/tests/misc/get_browser_error.phpt index f1d645b0263fd..f296ee063d68e 100644 --- a/ext/standard/tests/misc/get_browser_error.phpt +++ b/ext/standard/tests/misc/get_browser_error.phpt @@ -88,5 +88,7 @@ array(34) { string(1) "0" } +Deprecated: Implicit conversion from string "foobar" to true, only "", "0" or "1" are allowed in %s on line %d + Warning: get_browser(): HTTP_USER_AGENT variable is not set, cannot determine user agent name in %s on line %d bool(false) diff --git a/ext/standard/tests/strings/strstr.phpt b/ext/standard/tests/strings/strstr.phpt index 0d4065b54fb2b..87880b3ea9bd5 100644 --- a/ext/standard/tests/strings/strstr.phpt +++ b/ext/standard/tests/strings/strstr.phpt @@ -353,6 +353,8 @@ abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789" + +Deprecated: Implicit conversion from string "c" to true, only "", "0" or "1" are allowed in %s on line %d bool(false) DONE diff --git a/ext/standard/tests/strings/substr_compare.phpt b/ext/standard/tests/strings/substr_compare.phpt index 51d093a65fa22..21fd57c006ca7 100644 --- a/ext/standard/tests/strings/substr_compare.phpt +++ b/ext/standard/tests/strings/substr_compare.phpt @@ -20,7 +20,7 @@ try { } catch (\ValueError $e) { echo $e->getMessage() . "\n"; } -var_dump(substr_compare("abcde", "abc", -1, NULL, -5) > 0); +var_dump(substr_compare("abcde", "abc", -1, NULL) > 0); ?> --EXPECT-- bool(true) From 4004562751e7ed8066f4f7844ea1f6e14e226ad7 Mon Sep 17 00:00:00 2001 From: Andreas Leathley Date: Mon, 16 May 2022 19:04:26 +0200 Subject: [PATCH 02/10] Avoid bool deprecations in iterator tests --- ext/phar/tests/phar_buildfromiterator4.phpt | 2 +- ext/phar/tests/phar_buildfromiterator6.phpt | 2 +- ext/phar/tests/phar_buildfromiterator7.phpt | 2 +- ext/phar/tests/tar/phar_buildfromiterator4.phpt | 2 +- ext/phar/tests/tar/phar_buildfromiterator6.phpt | 2 +- ext/phar/tests/tar/phar_buildfromiterator7.phpt | 2 +- ext/phar/tests/zip/phar_buildfromiterator4.phpt | 2 +- ext/phar/tests/zip/phar_buildfromiterator6.phpt | 2 +- ext/phar/tests/zip/phar_buildfromiterator7.phpt | 2 +- tests/classes/iterators_008.phpt | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/ext/phar/tests/phar_buildfromiterator4.phpt b/ext/phar/tests/phar_buildfromiterator4.phpt index e7bccc27c956e..b4c225f17b32b 100644 --- a/ext/phar/tests/phar_buildfromiterator4.phpt +++ b/ext/phar/tests/phar_buildfromiterator4.phpt @@ -28,7 +28,7 @@ class myIterator implements Iterator } function valid(): bool { echo "valid\n"; - return current($this->a); + return current($this->a) == true; } function rewind(): void { echo "rewind\n"; diff --git a/ext/phar/tests/phar_buildfromiterator6.phpt b/ext/phar/tests/phar_buildfromiterator6.phpt index 4e4f09f74aa7a..cd756e98e223b 100644 --- a/ext/phar/tests/phar_buildfromiterator6.phpt +++ b/ext/phar/tests/phar_buildfromiterator6.phpt @@ -28,7 +28,7 @@ class myIterator implements Iterator } function valid(): bool { echo "valid\n"; - return current($this->a); + return current($this->a) == true; } function rewind(): void { echo "rewind\n"; diff --git a/ext/phar/tests/phar_buildfromiterator7.phpt b/ext/phar/tests/phar_buildfromiterator7.phpt index 646bcdac2a5c9..26b151eeaa64c 100644 --- a/ext/phar/tests/phar_buildfromiterator7.phpt +++ b/ext/phar/tests/phar_buildfromiterator7.phpt @@ -28,7 +28,7 @@ class myIterator implements Iterator } function valid(): bool { echo "valid\n"; - return current($this->a); + return current($this->a) == true; } function rewind(): void { echo "rewind\n"; diff --git a/ext/phar/tests/tar/phar_buildfromiterator4.phpt b/ext/phar/tests/tar/phar_buildfromiterator4.phpt index 8fa55768b082f..45d724a520a6d 100644 --- a/ext/phar/tests/tar/phar_buildfromiterator4.phpt +++ b/ext/phar/tests/tar/phar_buildfromiterator4.phpt @@ -28,7 +28,7 @@ class myIterator implements Iterator } function valid(): bool { echo "valid\n"; - return current($this->a); + return current($this->a) == true; } function rewind(): void { echo "rewind\n"; diff --git a/ext/phar/tests/tar/phar_buildfromiterator6.phpt b/ext/phar/tests/tar/phar_buildfromiterator6.phpt index 918203697998f..f0d2c10137020 100644 --- a/ext/phar/tests/tar/phar_buildfromiterator6.phpt +++ b/ext/phar/tests/tar/phar_buildfromiterator6.phpt @@ -28,7 +28,7 @@ class myIterator implements Iterator } function valid(): bool { echo "valid\n"; - return current($this->a); + return current($this->a) == true; } function rewind(): void { echo "rewind\n"; diff --git a/ext/phar/tests/tar/phar_buildfromiterator7.phpt b/ext/phar/tests/tar/phar_buildfromiterator7.phpt index 297b40b5eedda..1ff8ea924d96b 100644 --- a/ext/phar/tests/tar/phar_buildfromiterator7.phpt +++ b/ext/phar/tests/tar/phar_buildfromiterator7.phpt @@ -28,7 +28,7 @@ class myIterator implements Iterator } function valid(): bool { echo "valid\n"; - return current($this->a); + return current($this->a) == true; } function rewind(): void { echo "rewind\n"; diff --git a/ext/phar/tests/zip/phar_buildfromiterator4.phpt b/ext/phar/tests/zip/phar_buildfromiterator4.phpt index 8c1096754bf25..c8633bd75cfcb 100644 --- a/ext/phar/tests/zip/phar_buildfromiterator4.phpt +++ b/ext/phar/tests/zip/phar_buildfromiterator4.phpt @@ -28,7 +28,7 @@ class myIterator implements Iterator } function valid(): bool { echo "valid\n"; - return current($this->a); + return current($this->a) == true; } function rewind(): void { echo "rewind\n"; diff --git a/ext/phar/tests/zip/phar_buildfromiterator6.phpt b/ext/phar/tests/zip/phar_buildfromiterator6.phpt index 9d9140bc3433a..97783a3161258 100644 --- a/ext/phar/tests/zip/phar_buildfromiterator6.phpt +++ b/ext/phar/tests/zip/phar_buildfromiterator6.phpt @@ -28,7 +28,7 @@ class myIterator implements Iterator } function valid(): bool { echo "valid\n"; - return current($this->a); + return current($this->a) == true; } function rewind(): void { echo "rewind\n"; diff --git a/ext/phar/tests/zip/phar_buildfromiterator7.phpt b/ext/phar/tests/zip/phar_buildfromiterator7.phpt index f62be404a1e08..aaa7ed1f99cae 100644 --- a/ext/phar/tests/zip/phar_buildfromiterator7.phpt +++ b/ext/phar/tests/zip/phar_buildfromiterator7.phpt @@ -28,7 +28,7 @@ class myIterator implements Iterator } function valid(): bool { echo "valid\n"; - return current($this->a); + return current($this->a) == true; } function rewind(): void { echo "rewind\n"; diff --git a/tests/classes/iterators_008.phpt b/tests/classes/iterators_008.phpt index 679bcc384b291..8ba3b8e857554 100644 --- a/tests/classes/iterators_008.phpt +++ b/tests/classes/iterators_008.phpt @@ -10,7 +10,7 @@ class D extends C implements Iterator { public function valid(): bool { echo __METHOD__ . "($this->counter)\n"; - return $this->counter; + return $this->counter == true; } public function next(): void { From 289298ab4694ebc9b1a71dcbdf159eb8838f0114 Mon Sep 17 00:00:00 2001 From: Andreas Leathley Date: Mon, 16 May 2022 19:26:43 +0200 Subject: [PATCH 03/10] Fix wrong bool conversion in test suite --- run-tests.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run-tests.php b/run-tests.php index 8b4061e1c84b8..d7b6a9a0310b6 100755 --- a/run-tests.php +++ b/run-tests.php @@ -1150,7 +1150,7 @@ function test_sort($a, $b): int // Send Email to QA Team // -function mail_qa_team(string $data, bool $status = false): bool +function mail_qa_team(string $data, string $status = 'failed'): bool { $url_bits = parse_url(QA_SUBMISSION_PAGE); From 779cfe729fa019a6f944d3a548c92b05b1a6e410 Mon Sep 17 00:00:00 2001 From: Andreas Leathley Date: Mon, 16 May 2022 19:44:33 +0200 Subject: [PATCH 04/10] Fix unexpectedly affected tests from deprecation --- ext/gd/tests/imageantialias_error2.phpt | 21 ------------------- ext/gmp/tests/gmp_setbit.phpt | 2 +- ext/intl/tests/rbbiter___construct_basic.phpt | 2 +- ext/mysqli/tests/write_property.phpt | 4 +--- 4 files changed, 3 insertions(+), 26 deletions(-) delete mode 100644 ext/gd/tests/imageantialias_error2.phpt diff --git a/ext/gd/tests/imageantialias_error2.phpt b/ext/gd/tests/imageantialias_error2.phpt deleted file mode 100644 index 40f4d64a12b6e..0000000000000 --- a/ext/gd/tests/imageantialias_error2.phpt +++ /dev/null @@ -1,21 +0,0 @@ ---TEST-- -Testing wrong parameter passing in imageantialias() of GD library ---CREDITS-- -Guilherme Blanco -#testfest PHPSP on 2009-06-20 ---EXTENSIONS-- -gd ---FILE-- - ---EXPECT-- -bool(true) diff --git a/ext/gmp/tests/gmp_setbit.phpt b/ext/gmp/tests/gmp_setbit.phpt index b00393faf97b4..553718c512f49 100644 --- a/ext/gmp/tests/gmp_setbit.phpt +++ b/ext/gmp/tests/gmp_setbit.phpt @@ -6,7 +6,7 @@ gmp getMessage(), "\n"; } diff --git a/ext/mysqli/tests/write_property.phpt b/ext/mysqli/tests/write_property.phpt index e54f7387281c0..678029cdecfa0 100644 --- a/ext/mysqli/tests/write_property.phpt +++ b/ext/mysqli/tests/write_property.phpt @@ -15,9 +15,7 @@ try { $driver->reconnect = 0; var_dump($driver->reconnect); -$str = '4'; -$str .= '2'; -$driver->reconnect = $str; +$driver->reconnect = 1; var_dump($driver->reconnect); try { $driver->reconnect = []; From 646e65ebab9da3a7c29f2af78c716f1c3c05f6f4 Mon Sep 17 00:00:00 2001 From: Andreas Leathley Date: Mon, 16 May 2022 20:55:00 +0200 Subject: [PATCH 05/10] Make more tests pass / fixes for bool coercions --- Zend/tests/type_declarations/scalar_basic.phpt | 2 +- Zend/tests/type_declarations/scalar_return_basic_64bit.phpt | 2 +- Zend/zend_operators.c | 2 +- ext/imap/tests/imap_bodystruct_basic.phpt | 2 +- ext/snmp/tests/snmp-object-properties.phpt | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Zend/tests/type_declarations/scalar_basic.phpt b/Zend/tests/type_declarations/scalar_basic.phpt index ab1da10480f9d..82e7d5bd8bc81 100644 --- a/Zend/tests/type_declarations/scalar_basic.phpt +++ b/Zend/tests/type_declarations/scalar_basic.phpt @@ -247,7 +247,7 @@ bool(true) bool(false) *** Trying int(%d) -E_DEPRECATED: Implicit conversion from integer 9223372036854775807 to true, only 0 or 1 are allowed on line %d +E_DEPRECATED: Implicit conversion from integer -1 to true, only 0 or 1 are allowed on line %d bool(true) *** Trying float(NAN) diff --git a/Zend/tests/type_declarations/scalar_return_basic_64bit.phpt b/Zend/tests/type_declarations/scalar_return_basic_64bit.phpt index fb4b6f14dc6c7..5f73b26a67a3a 100644 --- a/Zend/tests/type_declarations/scalar_return_basic_64bit.phpt +++ b/Zend/tests/type_declarations/scalar_return_basic_64bit.phpt @@ -194,7 +194,7 @@ bool(true) *** Trying string(0) "" bool(false) *** Trying int(9223372036854775807) -E_DEPRECATED: Implicit conversion from integer 9223372036854775807 to true, only 0 or 1 are allowed on line %d +E_DEPRECATED: Implicit conversion from integer -1 to true, only 0 or 1 are allowed on line %d bool(true) *** Trying float(NAN) E_DEPRECATED: Implicit conversion from float NAN to true, only 0 or 1 are allowed on line %d diff --git a/Zend/zend_operators.c b/Zend/zend_operators.c index 3738bf4dc53d7..f878e00f75cf6 100644 --- a/Zend/zend_operators.c +++ b/Zend/zend_operators.c @@ -842,7 +842,7 @@ ZEND_API void ZEND_COLD zend_incompatible_double_to_bool_error(double d) } ZEND_API void ZEND_COLD zend_incompatible_long_to_bool_error(const zend_long l) { - zend_error(E_DEPRECATED, "Implicit conversion from integer %ld to true, only 0 or 1 are allowed", l); + zend_error(E_DEPRECATED, "Implicit conversion from integer %d to true, only 0 or 1 are allowed", (int)l); } ZEND_API void ZEND_COLD zend_incompatible_string_to_bool_error(const zend_string *s) { diff --git a/ext/imap/tests/imap_bodystruct_basic.phpt b/ext/imap/tests/imap_bodystruct_basic.phpt index 84a6edc7e37a4..3c98bed23ec7c 100644 --- a/ext/imap/tests/imap_bodystruct_basic.phpt +++ b/ext/imap/tests/imap_bodystruct_basic.phpt @@ -12,7 +12,7 @@ echo "*** Testing string imap_bodystruct : basic functionality ***\n"; require_once(__DIR__.'/setup/imap_include.inc'); echo "Create a new mailbox for test and add a multipart msgs\n"; -$imap_stream = setup_test_mailbox("imapbodystructbasic", 1, $mailbox, "multipart"); +$imap_stream = setup_test_mailbox("imapbodystructbasic", 1, $mailbox, true); echo "\nGet and validate structure of body part 1\n"; diff --git a/ext/snmp/tests/snmp-object-properties.phpt b/ext/snmp/tests/snmp-object-properties.phpt index a8fccd406b7e3..45ab73900dd5f 100644 --- a/ext/snmp/tests/snmp-object-properties.phpt +++ b/ext/snmp/tests/snmp-object-properties.phpt @@ -37,7 +37,7 @@ $session->enum_print = "1"; $session->quick_print = "1"; $session->valueretrieval = "1"; $session->oid_output_format = "3"; -$session->oid_increasing_check = "45"; +$session->oid_increasing_check = "1"; var_dump($session); From cca88fe246de71ddaec2d8d5b10062d87da03770 Mon Sep 17 00:00:00 2001 From: Andreas Leathley Date: Mon, 16 May 2022 22:07:28 +0200 Subject: [PATCH 06/10] Refactor error functions into one --- Zend/tests/type_declarations/scalar_basic.phpt | 2 +- .../scalar_return_basic_64bit.phpt | 2 +- Zend/zend_API.c | 8 +------- Zend/zend_operators.c | 18 ++++++++---------- Zend/zend_operators.h | 4 +--- 5 files changed, 12 insertions(+), 22 deletions(-) diff --git a/Zend/tests/type_declarations/scalar_basic.phpt b/Zend/tests/type_declarations/scalar_basic.phpt index 82e7d5bd8bc81..209b5721b1f9b 100644 --- a/Zend/tests/type_declarations/scalar_basic.phpt +++ b/Zend/tests/type_declarations/scalar_basic.phpt @@ -247,7 +247,7 @@ bool(true) bool(false) *** Trying int(%d) -E_DEPRECATED: Implicit conversion from integer -1 to true, only 0 or 1 are allowed on line %d +E_DEPRECATED: Implicit conversion from integer %d to true, only 0 or 1 are allowed on line %d bool(true) *** Trying float(NAN) diff --git a/Zend/tests/type_declarations/scalar_return_basic_64bit.phpt b/Zend/tests/type_declarations/scalar_return_basic_64bit.phpt index 5f73b26a67a3a..dad0076148870 100644 --- a/Zend/tests/type_declarations/scalar_return_basic_64bit.phpt +++ b/Zend/tests/type_declarations/scalar_return_basic_64bit.phpt @@ -194,7 +194,7 @@ bool(true) *** Trying string(0) "" bool(false) *** Trying int(9223372036854775807) -E_DEPRECATED: Implicit conversion from integer -1 to true, only 0 or 1 are allowed on line %d +E_DEPRECATED: Implicit conversion from integer %s to true, only 0 or 1 are allowed on line %d bool(true) *** Trying float(NAN) E_DEPRECATED: Implicit conversion from float NAN to true, only 0 or 1 are allowed on line %d diff --git a/Zend/zend_API.c b/Zend/zend_API.c index ddc98a1586e28..dad6faa9c41b2 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -477,13 +477,7 @@ ZEND_API bool ZEND_FASTCALL zend_parse_arg_bool_weak(zval *arg, bool *dest, uint /* Check arg_num is not (uint32_t)-1, as otherwise its called by * zend_verify_weak_scalar_type_hint_no_sideeffect() */ if (arg_num != (uint32_t)-1) { - if (Z_TYPE_P(arg) == IS_DOUBLE) { - zend_incompatible_double_to_bool_error(Z_DVAL_P(arg)); - } else if (Z_TYPE_P(arg) == IS_LONG) { - zend_incompatible_long_to_bool_error(Z_LVAL_P(arg)); - } else if (Z_TYPE_P(arg) == IS_STRING) { - zend_incompatible_string_to_bool_error(Z_STR_P(arg)); - } + zend_incompatible_scalar_to_bool_error(arg); } if (UNEXPECTED(EG(exception))) { return 0; diff --git a/Zend/zend_operators.c b/Zend/zend_operators.c index f878e00f75cf6..14142e9cbf60b 100644 --- a/Zend/zend_operators.c +++ b/Zend/zend_operators.c @@ -836,17 +836,15 @@ ZEND_API void ZEND_COLD zend_incompatible_string_to_long_error(const zend_string zend_error(E_DEPRECATED, "Implicit conversion from float-string \"%s\" to int loses precision", ZSTR_VAL(s)); } -ZEND_API void ZEND_COLD zend_incompatible_double_to_bool_error(double d) +ZEND_API void ZEND_COLD zend_incompatible_scalar_to_bool_error(zval *arg) { - zend_error_unchecked(E_DEPRECATED, "Implicit conversion from float %.*H to true, only 0 or 1 are allowed", -1, d); -} -ZEND_API void ZEND_COLD zend_incompatible_long_to_bool_error(const zend_long l) -{ - zend_error(E_DEPRECATED, "Implicit conversion from integer %d to true, only 0 or 1 are allowed", (int)l); -} -ZEND_API void ZEND_COLD zend_incompatible_string_to_bool_error(const zend_string *s) -{ - zend_error(E_DEPRECATED, "Implicit conversion from string \"%s\" to true, only \"\", \"0\" or \"1\" are allowed", ZSTR_VAL(s)); + if (Z_TYPE_P(arg) == IS_DOUBLE) { + zend_error_unchecked(E_DEPRECATED, "Implicit conversion from float %.*H to true, only 0 or 1 are allowed", -1, Z_DVAL_P(arg)); + } else if (Z_TYPE_P(arg) == IS_LONG) { + zend_error(E_DEPRECATED, "Implicit conversion from integer %ld to true, only 0 or 1 are allowed", (long)Z_LVAL_P(arg)); + } else if (Z_TYPE_P(arg) == IS_STRING) { + zend_error(E_DEPRECATED, "Implicit conversion from string \"%s\" to true, only \"\", \"0\" or \"1\" are allowed", ZSTR_VAL(Z_STR_P(arg))); + } } ZEND_API zend_long ZEND_FASTCALL zval_get_long_func(zval *op, bool is_strict) /* {{{ */ diff --git a/Zend/zend_operators.h b/Zend/zend_operators.h index cab179911c24e..4d0a420cae210 100644 --- a/Zend/zend_operators.h +++ b/Zend/zend_operators.h @@ -170,9 +170,7 @@ static zend_always_inline bool zend_scalar_is_valid_bool(zval *arg) { ZEND_API void zend_incompatible_double_to_long_error(double d); ZEND_API void zend_incompatible_string_to_long_error(const zend_string *s); -ZEND_API void zend_incompatible_double_to_bool_error(double d); -ZEND_API void zend_incompatible_long_to_bool_error(const zend_long l); -ZEND_API void zend_incompatible_string_to_bool_error(const zend_string *s); +ZEND_API void zend_incompatible_scalar_to_bool_error(zval *arg); static zend_always_inline zend_long zend_dval_to_lval_safe(double d) { From 65eb7b8255fe0d1b4f91e616724e3ef7cd1481e5 Mon Sep 17 00:00:00 2001 From: Andreas Leathley Date: Mon, 16 May 2022 22:47:13 +0200 Subject: [PATCH 07/10] Adjust max int values in tests --- Zend/tests/type_declarations/scalar_return_basic.phpt | 2 +- Zend/tests/type_declarations/scalar_return_basic_64bit.phpt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Zend/tests/type_declarations/scalar_return_basic.phpt b/Zend/tests/type_declarations/scalar_return_basic.phpt index 9ab98a83e1cf1..80444832fbe86 100644 --- a/Zend/tests/type_declarations/scalar_return_basic.phpt +++ b/Zend/tests/type_declarations/scalar_return_basic.phpt @@ -194,7 +194,7 @@ bool(true) *** Trying string(0) "" bool(false) *** Trying int(2147483647) -E_DEPRECATED: Implicit conversion from integer -1 to true, only 0 or 1 are allowed on line %d +E_DEPRECATED: Implicit conversion from integer 2147483647 to true, only 0 or 1 are allowed on line %d bool(true) *** Trying float(NAN) E_DEPRECATED: Implicit conversion from float NAN to true, only 0 or 1 are allowed on line %d diff --git a/Zend/tests/type_declarations/scalar_return_basic_64bit.phpt b/Zend/tests/type_declarations/scalar_return_basic_64bit.phpt index dad0076148870..fb4b6f14dc6c7 100644 --- a/Zend/tests/type_declarations/scalar_return_basic_64bit.phpt +++ b/Zend/tests/type_declarations/scalar_return_basic_64bit.phpt @@ -194,7 +194,7 @@ bool(true) *** Trying string(0) "" bool(false) *** Trying int(9223372036854775807) -E_DEPRECATED: Implicit conversion from integer %s to true, only 0 or 1 are allowed on line %d +E_DEPRECATED: Implicit conversion from integer 9223372036854775807 to true, only 0 or 1 are allowed on line %d bool(true) *** Trying float(NAN) E_DEPRECATED: Implicit conversion from float NAN to true, only 0 or 1 are allowed on line %d From f675f0f239b98061c231cb902b8a04b012283b01 Mon Sep 17 00:00:00 2001 From: Andreas Date: Tue, 17 May 2022 13:10:49 +0200 Subject: [PATCH 08/10] Use canonical type name int instead of integer Co-authored-by: George Peter Banyard --- Zend/zend_operators.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Zend/zend_operators.c b/Zend/zend_operators.c index 14142e9cbf60b..6e304230d3732 100644 --- a/Zend/zend_operators.c +++ b/Zend/zend_operators.c @@ -841,7 +841,7 @@ ZEND_API void ZEND_COLD zend_incompatible_scalar_to_bool_error(zval *arg) if (Z_TYPE_P(arg) == IS_DOUBLE) { zend_error_unchecked(E_DEPRECATED, "Implicit conversion from float %.*H to true, only 0 or 1 are allowed", -1, Z_DVAL_P(arg)); } else if (Z_TYPE_P(arg) == IS_LONG) { - zend_error(E_DEPRECATED, "Implicit conversion from integer %ld to true, only 0 or 1 are allowed", (long)Z_LVAL_P(arg)); + zend_error(E_DEPRECATED, "Implicit conversion from int %ld to true, only 0 or 1 are allowed", (long)Z_LVAL_P(arg)); } else if (Z_TYPE_P(arg) == IS_STRING) { zend_error(E_DEPRECATED, "Implicit conversion from string \"%s\" to true, only \"\", \"0\" or \"1\" are allowed", ZSTR_VAL(Z_STR_P(arg))); } From 70a6ef536e8883a1deef259ec8754113145a82a4 Mon Sep 17 00:00:00 2001 From: Andreas Leathley Date: Tue, 17 May 2022 13:24:07 +0200 Subject: [PATCH 09/10] Change deprecated messages in tests from integer to int --- Zend/tests/scalar_to_bool/warnings_int_non_zero_or_one.phpt | 6 +++--- Zend/tests/type_declarations/scalar_basic.phpt | 2 +- Zend/tests/type_declarations/scalar_return_basic.phpt | 2 +- Zend/tests/type_declarations/scalar_return_basic_64bit.phpt | 2 +- .../type_declarations/union_types/type_checking_weak.phpt | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Zend/tests/scalar_to_bool/warnings_int_non_zero_or_one.phpt b/Zend/tests/scalar_to_bool/warnings_int_non_zero_or_one.phpt index e187a473917ec..7db0468be63bb 100644 --- a/Zend/tests/scalar_to_bool/warnings_int_non_zero_or_one.phpt +++ b/Zend/tests/scalar_to_bool/warnings_int_non_zero_or_one.phpt @@ -28,13 +28,13 @@ var_dump($instance->a); --EXPECTF-- Function calls: -Deprecated: Implicit conversion from integer 5 to true, only 0 or 1 are allowed in %s on line %d +Deprecated: Implicit conversion from int 5 to true, only 0 or 1 are allowed in %s on line %d bool(true) Function returns: -Deprecated: Implicit conversion from integer 3 to true, only 0 or 1 are allowed in %s on line %d +Deprecated: Implicit conversion from int 3 to true, only 0 or 1 are allowed in %s on line %d bool(true) Typed property assignment: -Deprecated: Implicit conversion from integer 13 to true, only 0 or 1 are allowed in %s on line %d +Deprecated: Implicit conversion from int 13 to true, only 0 or 1 are allowed in %s on line %d bool(true) diff --git a/Zend/tests/type_declarations/scalar_basic.phpt b/Zend/tests/type_declarations/scalar_basic.phpt index 209b5721b1f9b..9498eee275714 100644 --- a/Zend/tests/type_declarations/scalar_basic.phpt +++ b/Zend/tests/type_declarations/scalar_basic.phpt @@ -247,7 +247,7 @@ bool(true) bool(false) *** Trying int(%d) -E_DEPRECATED: Implicit conversion from integer %d to true, only 0 or 1 are allowed on line %d +E_DEPRECATED: Implicit conversion from int %d to true, only 0 or 1 are allowed on line %d bool(true) *** Trying float(NAN) diff --git a/Zend/tests/type_declarations/scalar_return_basic.phpt b/Zend/tests/type_declarations/scalar_return_basic.phpt index 80444832fbe86..3c1d4df43bf99 100644 --- a/Zend/tests/type_declarations/scalar_return_basic.phpt +++ b/Zend/tests/type_declarations/scalar_return_basic.phpt @@ -194,7 +194,7 @@ bool(true) *** Trying string(0) "" bool(false) *** Trying int(2147483647) -E_DEPRECATED: Implicit conversion from integer 2147483647 to true, only 0 or 1 are allowed on line %d +E_DEPRECATED: Implicit conversion from int 2147483647 to true, only 0 or 1 are allowed on line %d bool(true) *** Trying float(NAN) E_DEPRECATED: Implicit conversion from float NAN to true, only 0 or 1 are allowed on line %d diff --git a/Zend/tests/type_declarations/scalar_return_basic_64bit.phpt b/Zend/tests/type_declarations/scalar_return_basic_64bit.phpt index fb4b6f14dc6c7..f34c841937c91 100644 --- a/Zend/tests/type_declarations/scalar_return_basic_64bit.phpt +++ b/Zend/tests/type_declarations/scalar_return_basic_64bit.phpt @@ -194,7 +194,7 @@ bool(true) *** Trying string(0) "" bool(false) *** Trying int(9223372036854775807) -E_DEPRECATED: Implicit conversion from integer 9223372036854775807 to true, only 0 or 1 are allowed on line %d +E_DEPRECATED: Implicit conversion from int 9223372036854775807 to true, only 0 or 1 are allowed on line %d bool(true) *** Trying float(NAN) E_DEPRECATED: Implicit conversion from float NAN to true, only 0 or 1 are allowed on line %d diff --git a/Zend/tests/type_declarations/union_types/type_checking_weak.phpt b/Zend/tests/type_declarations/union_types/type_checking_weak.phpt index 6f2c5e1be65fb..838e4374375d8 100644 --- a/Zend/tests/type_declarations/union_types/type_checking_weak.phpt +++ b/Zend/tests/type_declarations/union_types/type_checking_weak.phpt @@ -189,7 +189,7 @@ new stdClass => Argument ... must be of type array|string, stdClass given new WithToString => "__toString()" Type bool|array: -42 => true (Implicit conversion from integer 42 to true, only 0 or 1 are allowed) +42 => true (Implicit conversion from int 42 to true, only 0 or 1 are allowed) 42.0 => true (Implicit conversion from float 42 to true, only 0 or 1 are allowed) INF => true (Implicit conversion from float INF to true, only 0 or 1 are allowed) "42" => true (Implicit conversion from string "42" to true, only "", "0" or "1" are allowed) From 6dd99482afd4733a841d3e030a4e787cefdfa401 Mon Sep 17 00:00:00 2001 From: Andreas Leathley Date: Thu, 19 May 2022 16:24:39 +0200 Subject: [PATCH 10/10] More succinct code in scalar_is_valid_bool + in tests --- Zend/zend_operators.h | 14 +++++--------- ext/gmp/tests/gmp_setbit.phpt | 10 +++++----- ext/phar/tests/phar_buildfromiterator4.phpt | 2 +- ext/phar/tests/phar_buildfromiterator6.phpt | 2 +- ext/phar/tests/phar_buildfromiterator7.phpt | 2 +- ext/phar/tests/tar/phar_buildfromiterator4.phpt | 2 +- ext/phar/tests/tar/phar_buildfromiterator6.phpt | 2 +- ext/phar/tests/tar/phar_buildfromiterator7.phpt | 2 +- ext/phar/tests/zip/phar_buildfromiterator4.phpt | 2 +- ext/phar/tests/zip/phar_buildfromiterator6.phpt | 2 +- ext/phar/tests/zip/phar_buildfromiterator7.phpt | 2 +- tests/classes/iterators_008.phpt | 2 +- 12 files changed, 20 insertions(+), 24 deletions(-) diff --git a/Zend/zend_operators.h b/Zend/zend_operators.h index 4d0a420cae210..ecccaed6da6b8 100644 --- a/Zend/zend_operators.h +++ b/Zend/zend_operators.h @@ -139,32 +139,28 @@ static zend_always_inline bool zend_is_long_compatible(double d, zend_long l) { } static zend_always_inline bool zend_scalar_is_valid_bool(zval *arg) { - bool result = 0; - switch (Z_TYPE_P(arg)) { case IS_TRUE: case IS_FALSE: - result = 1; + return true; break; case IS_LONG: if (Z_LVAL_P(arg) == 0 || Z_LVAL_P(arg) == 1) { - result = 1; + return true; } break; case IS_DOUBLE: if (Z_DVAL_P(arg) == 0.0 || Z_DVAL_P(arg) == 1.0) { - result = 1; + return true; } break; case IS_STRING: if (Z_STRLEN_P(arg) == 0 || (Z_STRLEN_P(arg) == 1 && (Z_STRVAL_P(arg)[0] == '0' || Z_STRVAL_P(arg)[0] == '1'))) { - result = 1; + return true; } break; - default: - break; } - return result; + return false; } ZEND_API void zend_incompatible_double_to_long_error(double d); diff --git a/ext/gmp/tests/gmp_setbit.phpt b/ext/gmp/tests/gmp_setbit.phpt index 553718c512f49..e0a181baa9fdc 100644 --- a/ext/gmp/tests/gmp_setbit.phpt +++ b/ext/gmp/tests/gmp_setbit.phpt @@ -6,27 +6,27 @@ gmp getMessage() . \PHP_EOL; } var_dump(gmp_strval($n)); $n = gmp_init(5); -gmp_setbit($n, 2, 0); +gmp_setbit($n, 2, false); var_dump(gmp_strval($n)); $n = gmp_init(5); -gmp_setbit($n, 1, 1); +gmp_setbit($n, 1, true); var_dump(gmp_strval($n)); $n = gmp_init("100000000000"); -gmp_setbit($n, 23, 1); +gmp_setbit($n, 23, true); var_dump(gmp_strval($n)); gmp_setbit($n, 23, 0); diff --git a/ext/phar/tests/phar_buildfromiterator4.phpt b/ext/phar/tests/phar_buildfromiterator4.phpt index b4c225f17b32b..a412b2a2938b1 100644 --- a/ext/phar/tests/phar_buildfromiterator4.phpt +++ b/ext/phar/tests/phar_buildfromiterator4.phpt @@ -28,7 +28,7 @@ class myIterator implements Iterator } function valid(): bool { echo "valid\n"; - return current($this->a) == true; + return current($this->a) !== false; } function rewind(): void { echo "rewind\n"; diff --git a/ext/phar/tests/phar_buildfromiterator6.phpt b/ext/phar/tests/phar_buildfromiterator6.phpt index cd756e98e223b..2b9de5156d91c 100644 --- a/ext/phar/tests/phar_buildfromiterator6.phpt +++ b/ext/phar/tests/phar_buildfromiterator6.phpt @@ -28,7 +28,7 @@ class myIterator implements Iterator } function valid(): bool { echo "valid\n"; - return current($this->a) == true; + return current($this->a) !== false; } function rewind(): void { echo "rewind\n"; diff --git a/ext/phar/tests/phar_buildfromiterator7.phpt b/ext/phar/tests/phar_buildfromiterator7.phpt index 26b151eeaa64c..cd4b980fd3471 100644 --- a/ext/phar/tests/phar_buildfromiterator7.phpt +++ b/ext/phar/tests/phar_buildfromiterator7.phpt @@ -28,7 +28,7 @@ class myIterator implements Iterator } function valid(): bool { echo "valid\n"; - return current($this->a) == true; + return current($this->a) !== false; } function rewind(): void { echo "rewind\n"; diff --git a/ext/phar/tests/tar/phar_buildfromiterator4.phpt b/ext/phar/tests/tar/phar_buildfromiterator4.phpt index 45d724a520a6d..c15e40127074c 100644 --- a/ext/phar/tests/tar/phar_buildfromiterator4.phpt +++ b/ext/phar/tests/tar/phar_buildfromiterator4.phpt @@ -28,7 +28,7 @@ class myIterator implements Iterator } function valid(): bool { echo "valid\n"; - return current($this->a) == true; + return current($this->a) !== false; } function rewind(): void { echo "rewind\n"; diff --git a/ext/phar/tests/tar/phar_buildfromiterator6.phpt b/ext/phar/tests/tar/phar_buildfromiterator6.phpt index f0d2c10137020..fd265d9b067d7 100644 --- a/ext/phar/tests/tar/phar_buildfromiterator6.phpt +++ b/ext/phar/tests/tar/phar_buildfromiterator6.phpt @@ -28,7 +28,7 @@ class myIterator implements Iterator } function valid(): bool { echo "valid\n"; - return current($this->a) == true; + return current($this->a) !== false; } function rewind(): void { echo "rewind\n"; diff --git a/ext/phar/tests/tar/phar_buildfromiterator7.phpt b/ext/phar/tests/tar/phar_buildfromiterator7.phpt index 1ff8ea924d96b..d480d42d6b4a6 100644 --- a/ext/phar/tests/tar/phar_buildfromiterator7.phpt +++ b/ext/phar/tests/tar/phar_buildfromiterator7.phpt @@ -28,7 +28,7 @@ class myIterator implements Iterator } function valid(): bool { echo "valid\n"; - return current($this->a) == true; + return current($this->a) !== false; } function rewind(): void { echo "rewind\n"; diff --git a/ext/phar/tests/zip/phar_buildfromiterator4.phpt b/ext/phar/tests/zip/phar_buildfromiterator4.phpt index c8633bd75cfcb..690cb2c092722 100644 --- a/ext/phar/tests/zip/phar_buildfromiterator4.phpt +++ b/ext/phar/tests/zip/phar_buildfromiterator4.phpt @@ -28,7 +28,7 @@ class myIterator implements Iterator } function valid(): bool { echo "valid\n"; - return current($this->a) == true; + return current($this->a) !== false; } function rewind(): void { echo "rewind\n"; diff --git a/ext/phar/tests/zip/phar_buildfromiterator6.phpt b/ext/phar/tests/zip/phar_buildfromiterator6.phpt index 97783a3161258..fb8ffe4d785fe 100644 --- a/ext/phar/tests/zip/phar_buildfromiterator6.phpt +++ b/ext/phar/tests/zip/phar_buildfromiterator6.phpt @@ -28,7 +28,7 @@ class myIterator implements Iterator } function valid(): bool { echo "valid\n"; - return current($this->a) == true; + return current($this->a) !== false; } function rewind(): void { echo "rewind\n"; diff --git a/ext/phar/tests/zip/phar_buildfromiterator7.phpt b/ext/phar/tests/zip/phar_buildfromiterator7.phpt index aaa7ed1f99cae..a5e48617d2c14 100644 --- a/ext/phar/tests/zip/phar_buildfromiterator7.phpt +++ b/ext/phar/tests/zip/phar_buildfromiterator7.phpt @@ -28,7 +28,7 @@ class myIterator implements Iterator } function valid(): bool { echo "valid\n"; - return current($this->a) == true; + return current($this->a) !== false; } function rewind(): void { echo "rewind\n"; diff --git a/tests/classes/iterators_008.phpt b/tests/classes/iterators_008.phpt index 8ba3b8e857554..f39259588a535 100644 --- a/tests/classes/iterators_008.phpt +++ b/tests/classes/iterators_008.phpt @@ -10,7 +10,7 @@ class D extends C implements Iterator { public function valid(): bool { echo __METHOD__ . "($this->counter)\n"; - return $this->counter == true; + return $this->counter > 0; } public function next(): void {