From f23713bd53f4c2668d254888aef31bc328793640 Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Mon, 25 Aug 2025 17:47:32 +0200 Subject: [PATCH 1/8] core: Warn when non-representable floats are coerced to int --- Zend/Optimizer/sccp.c | 6 +- Zend/Optimizer/zend_inference.c | 1 + .../bitwise_not_precision_exception.phpt | 2 +- Zend/tests/bug46701.phpt | 10 +- Zend/tests/bug78340.phpt | 2 +- Zend/tests/falsetoarray_003.phpt | 2 +- Zend/tests/int_overflow_32bit.phpt | 11 +- Zend/tests/int_overflow_64bit.phpt | 8 +- Zend/tests/int_underflow_32bit.phpt | 10 +- ...rrayObject_container_offset_behaviour.phpt | 89 ++++++++ .../array_container_offset_behaviour.phpt | 89 ++++++++ Zend/tests/{ => offsets}/array_offset.phpt | 0 .../tests/{ => offsets}/array_offset_002.phpt | 2 +- .../false_container_offset_behaviour.phpt | 89 ++++++++ .../null_container_offset_behaviour.phpt | 87 +++++++ .../string_container_offset_behaviour.phpt | 95 +++++++- .../runtime_compile_time_binary_operands.phpt | 2 +- .../float_to_int}/dval_to_lval_32.phpt | 13 +- .../float_to_int}/dval_to_lval_64.phpt | 11 +- .../explicit_casts_should_not_warn.phpt | 14 +- .../explicit_casts_should_not_warn_32bit.phpt | 12 +- ...g_float_does_not_fit_zend_long_arrays.phpt | 11 +- ..._float_does_not_fit_zend_long_strings.phpt | 3 + ..._does_not_fit_zend_long_strings_32bit.phpt | 3 + .../type_coercion/int_special_values.phpt | 8 +- Zend/zend_compile.c | 31 ++- Zend/zend_execute.c | 66 +++--- Zend/zend_operators.c | 30 +-- Zend/zend_operators.h | 28 ++- ext/date/tests/bug79015.phpt | 1 + ext/intl/tests/gh13766.phpt | 2 +- ext/opcache/jit/zend_jit_helpers.c | 216 +++++++++--------- ext/opcache/tests/jit/add_011.phpt | 5 +- ext/opcache/tests/jit/array_elem_002.phpt | 2 +- ext/opcache/tests/jit/gh19669-001.phpt | 3 +- ext/opcache/tests/jit/gh19669-002.phpt | 3 +- .../tests/jit/reg_alloc_003_32bits.phpt | 2 +- ext/openssl/tests/openssl_decrypt_basic.phpt | 3 +- ext/standard/array.c | 18 +- .../gettype_settype_variation2.phpt | 12 + .../tests/general_functions/intval.phpt | 24 +- ext/standard/tests/math/bug30695.phpt | 16 +- ext/standard/tests/strings/bug47842.phpt | 4 +- ext/standard/tests/strings/pack.phpt | 22 +- ext/standard/tests/strings/pack64.phpt | 18 +- .../tests/strings/vprintf_variation12.phpt | 8 +- .../tests/strings/vprintf_variation14.phpt | 8 +- .../tests/strings/vprintf_variation15.phpt | 6 +- .../strings/vprintf_variation15_64bit.phpt | 4 +- .../tests/strings/vprintf_variation16.phpt | 8 +- .../tests/strings/vprintf_variation4.phpt | 4 +- main/php_variables.c | 2 +- tests/lang/bug27354.phpt | 2 +- .../operators/bitwiseNot_basiclong_64bit.phpt | 2 +- 54 files changed, 865 insertions(+), 265 deletions(-) rename Zend/tests/{ => offsets}/array_offset.phpt (100%) rename Zend/tests/{ => offsets}/array_offset_002.phpt (81%) rename Zend/tests/{ => type_coercion/float_to_int}/dval_to_lval_32.phpt (55%) rename Zend/tests/{ => type_coercion/float_to_int}/dval_to_lval_64.phpt (56%) diff --git a/Zend/Optimizer/sccp.c b/Zend/Optimizer/sccp.c index c1faf2a3fbe03..9b8216e589bea 100644 --- a/Zend/Optimizer/sccp.c +++ b/Zend/Optimizer/sccp.c @@ -371,7 +371,7 @@ static inline zend_result fetch_array_elem(zval **result, zval *op1, zval *op2) *result = zend_hash_index_find(Z_ARR_P(op1), Z_LVAL_P(op2)); return SUCCESS; case IS_DOUBLE: { - zend_long lval = zend_dval_to_lval(Z_DVAL_P(op2)); + zend_long lval = zend_dval_to_lval_silent(Z_DVAL_P(op2)); if (!zend_is_long_compatible(Z_DVAL_P(op2), lval)) { return FAILURE; } @@ -459,7 +459,7 @@ static inline zend_result ct_eval_del_array_elem(zval *result, const zval *key) zend_hash_index_del(Z_ARR_P(result), Z_LVAL_P(key)); break; case IS_DOUBLE: { - zend_long lval = zend_dval_to_lval(Z_DVAL_P(key)); + zend_long lval = zend_dval_to_lval_silent(Z_DVAL_P(key)); if (!zend_is_long_compatible(Z_DVAL_P(key), lval)) { return FAILURE; } @@ -504,7 +504,7 @@ static inline zend_result ct_eval_add_array_elem(zval *result, zval *value, cons value = zend_hash_index_update(Z_ARR_P(result), Z_LVAL_P(key), value); break; case IS_DOUBLE: { - zend_long lval = zend_dval_to_lval(Z_DVAL_P(key)); + zend_long lval = zend_dval_to_lval_silent(Z_DVAL_P(key)); if (!zend_is_long_compatible(Z_DVAL_P(key), lval)) { return FAILURE; } diff --git a/Zend/Optimizer/zend_inference.c b/Zend/Optimizer/zend_inference.c index 62e04cb0e306b..7f84ed55de60e 100644 --- a/Zend/Optimizer/zend_inference.c +++ b/Zend/Optimizer/zend_inference.c @@ -5283,6 +5283,7 @@ ZEND_API bool zend_may_throw_ex(const zend_op *opline, const zend_ssa_op *ssa_op case ZEND_CAST: switch (opline->extended_value) { case IS_LONG: + return (t1 & (MAY_BE_DOUBLE|MAY_BE_STRING|MAY_BE_OBJECT)); case IS_DOUBLE: return (t1 & MAY_BE_OBJECT); case IS_STRING: diff --git a/Zend/tests/bitwise_not_precision_exception.phpt b/Zend/tests/bitwise_not_precision_exception.phpt index fa821100464e7..30d2978db5d2d 100644 --- a/Zend/tests/bitwise_not_precision_exception.phpt +++ b/Zend/tests/bitwise_not_precision_exception.phpt @@ -12,4 +12,4 @@ try { } ?> --EXPECT-- -Implicit conversion from float INF to int loses precision +non-representable float INF was cast to int diff --git a/Zend/tests/bug46701.phpt b/Zend/tests/bug46701.phpt index e7cc823d85c5e..5196bf2c6c42a 100644 --- a/Zend/tests/bug46701.phpt +++ b/Zend/tests/bug46701.phpt @@ -27,11 +27,11 @@ new foo; ?> --EXPECTF-- -Deprecated: Implicit conversion from float 3428599296 to int loses precision in %s on line %d +Warning: non-representable float 3428599296 was cast to int in %s on line %d -Deprecated: Implicit conversion from float 3459455488 to int loses precision in %s on line %d +Warning: non-representable float 3459455488 was cast to int in %s on line %d -Deprecated: Implicit conversion from float 3459616768 to int loses precision in %s on line %d +Warning: non-representable float 3459616768 was cast to int in %s on line %d array(3) { [-866368000]=> int(1) @@ -41,10 +41,10 @@ array(3) { int(3) } -Deprecated: Implicit conversion from float 3459455488 to int loses precision in %s on line %d +Warning: non-representable float 3459455488 was cast to int in %s on line %d int(2) -Deprecated: Implicit conversion from float 3459616768 to int loses precision in %s on line %d +Warning: non-representable float 3459616768 was cast to int in %s on line %d array(1) { [-835350528]=> int(3) diff --git a/Zend/tests/bug78340.phpt b/Zend/tests/bug78340.phpt index 4012e83af6acd..22ea0c19353e9 100644 --- a/Zend/tests/bug78340.phpt +++ b/Zend/tests/bug78340.phpt @@ -32,7 +32,7 @@ class lib { function stream_stat() { return [ - 'dev' => 3632233996, + 'dev' => PHP_INT_MAX, 'size' => strlen($this->bytes), 'ino' => $this->ino ]; diff --git a/Zend/tests/falsetoarray_003.phpt b/Zend/tests/falsetoarray_003.phpt index 11b32771e1fc1..9b816c3c8efdc 100644 --- a/Zend/tests/falsetoarray_003.phpt +++ b/Zend/tests/falsetoarray_003.phpt @@ -11,6 +11,6 @@ $a=[]; ?> DONE --EXPECTF-- -Err: Implicit conversion from float %f to int loses precision +Err: non-representable float %f was cast to int Err: Undefined array key %i DONE diff --git a/Zend/tests/int_overflow_32bit.phpt b/Zend/tests/int_overflow_32bit.phpt index 15dce6eea7dcf..49f8f7a26397c 100644 --- a/Zend/tests/int_overflow_32bit.phpt +++ b/Zend/tests/int_overflow_32bit.phpt @@ -20,10 +20,19 @@ foreach ($doubles as $d) { echo "Done\n"; ?> ---EXPECT-- +--EXPECTF-- +Warning: non-representable float 2147483648 was cast to int in %s on line %d int(-2147483648) + +Warning: non-representable float 2147483649 was cast to int in %s on line %d int(-2147483647) + +Warning: non-representable float 2147483658 was cast to int in %s on line %d int(-2147483638) + +Warning: non-representable float 2147483748 was cast to int in %s on line %d int(-2147483548) + +Warning: non-representable float 2147484648 was cast to int in %s on line %d int(-2147482648) Done diff --git a/Zend/tests/int_overflow_64bit.phpt b/Zend/tests/int_overflow_64bit.phpt index 7c541250205c8..c4254d3c2a44c 100644 --- a/Zend/tests/int_overflow_64bit.phpt +++ b/Zend/tests/int_overflow_64bit.phpt @@ -22,10 +22,16 @@ foreach ($doubles as $d) { echo "Done\n"; ?> ---EXPECT-- +--EXPECTF-- int(9223372036854775807) + +Warning: non-representable float %f was cast to int in %s on line %d int(-9223372036854775808) + +Warning: non-representable float %f was cast to int in %s on line %d int(-9223372036854775808) + +Warning: non-representable float %f was cast to int in %s on line %d int(0) int(-9223372036854775808) int(-9223372036854775808) diff --git a/Zend/tests/int_underflow_32bit.phpt b/Zend/tests/int_underflow_32bit.phpt index 71464a758aeea..d4b87ee3e5de9 100644 --- a/Zend/tests/int_underflow_32bit.phpt +++ b/Zend/tests/int_underflow_32bit.phpt @@ -20,10 +20,18 @@ foreach ($doubles as $d) { echo "Done\n"; ?> ---EXPECT-- +--EXPECTF-- int(-2147483648) + +Warning: non-representable float -2147483649 was cast to int in %s on line %d int(2147483647) + +Warning: non-representable float -2147483658 was cast to int in %s on line %d int(2147483638) + +Warning: non-representable float -2147483748 was cast to int in %s on line %d int(2147483548) + +Warning: non-representable float -2147484648 was cast to int in %s on line %d int(2147482648) Done diff --git a/Zend/tests/offsets/ArrayObject_container_offset_behaviour.phpt b/Zend/tests/offsets/ArrayObject_container_offset_behaviour.phpt index c44c2df24f77b..107dab96be030 100644 --- a/Zend/tests/offsets/ArrayObject_container_offset_behaviour.phpt +++ b/Zend/tests/offsets/ArrayObject_container_offset_behaviour.phpt @@ -132,6 +132,93 @@ OUTPUT; $EXPECTED_OUTPUT_FLOAT_OFFSETS_REGEX = '/^' . expectf_to_regex(EXPECTF_OUTPUT_FLOAT_OFFSETS) . '$/s'; +const EXPECTF_OUTPUT_FLOAT_OOB_OFFSETS = << --EXPECT-- -Err: Implicit conversion from float 1.0E+20 to int loses precision +Err: non-representable float 1.0E+20 was cast to int array(0) { } diff --git a/Zend/tests/offsets/false_container_offset_behaviour.phpt b/Zend/tests/offsets/false_container_offset_behaviour.phpt index 736e51830a453..d10f6e424cd09 100644 --- a/Zend/tests/offsets/false_container_offset_behaviour.phpt +++ b/Zend/tests/offsets/false_container_offset_behaviour.phpt @@ -135,6 +135,93 @@ OUTPUT; $EXPECTED_OUTPUT_FLOAT_OFFSETS_REGEX = '/^' . expectf_to_regex(EXPECTF_OUTPUT_FLOAT_OFFSETS) . '$/s'; +const EXPECTF_OUTPUT_FLOAT_OOB_OFFSETS = << --FILE-- ---EXPECT-- +--EXPECTF-- +Warning: non-representable float -4.000000000000001E+21 was cast to int in %s on line %d int(-2056257536) + +Warning: non-representable float -4.0000000000000005E+21 was cast to int in %s on line %d int(-2055733248) + +Warning: non-representable float -4.0E+21 was cast to int in %s on line %d int(-2055208960) + +Warning: non-representable float -3.9999999999999995E+21 was cast to int in %s on line %d int(-2054684672) + +Warning: non-representable float -3.999999999999999E+21 was cast to int in %s on line %d int(-2054160384) + +Warning: non-representable float -2147483649.8 was cast to int in %s on line %d int(2147483647) diff --git a/Zend/tests/dval_to_lval_64.phpt b/Zend/tests/type_coercion/float_to_int/dval_to_lval_64.phpt similarity index 56% rename from Zend/tests/dval_to_lval_64.phpt rename to Zend/tests/type_coercion/float_to_int/dval_to_lval_64.phpt index b54f861bf55cf..d811d398114cc 100644 --- a/Zend/tests/dval_to_lval_64.phpt +++ b/Zend/tests/type_coercion/float_to_int/dval_to_lval_64.phpt @@ -21,9 +21,18 @@ if (PHP_INT_SIZE != 8) } ?> ---EXPECT-- +--EXPECTF-- +Warning: non-representable float -4.000000000000001E+21 was cast to int in %s on line %d int(2943463994971652096) + +Warning: non-representable float -4.0000000000000005E+21 was cast to int in %s on line %d int(2943463994972176384) + +Warning: non-representable float -4.0E+21 was cast to int in %s on line %d int(2943463994972700672) + +Warning: non-representable float -3.9999999999999995E+21 was cast to int in %s on line %d int(2943463994973224960) + +Warning: non-representable float -3.999999999999999E+21 was cast to int in %s on line %d int(2943463994973749248) diff --git a/Zend/tests/type_coercion/float_to_int/explicit_casts_should_not_warn.phpt b/Zend/tests/type_coercion/float_to_int/explicit_casts_should_not_warn.phpt index 71c68e57574bf..f1273847321b0 100644 --- a/Zend/tests/type_coercion/float_to_int/explicit_casts_should_not_warn.phpt +++ b/Zend/tests/type_coercion/float_to_int/explicit_casts_should_not_warn.phpt @@ -1,5 +1,5 @@ --TEST-- -Explicit (int) cast must not warn +Explicit (int) cast must not warn if value is representable --SKIPIF-- ---EXPECT-- +--EXPECTF-- int(3) int(3) + +Warning: non-representable float 1.0E+121 was cast to int in %s on line %d int(0) + +Warning: non-representable float 1.0E+301 was cast to int in %s on line %d int(0) + +Warning: non-representable float NAN was cast to int in %s on line %d int(0) int(3) int(3) + +Warning: non-representable float-string 1.0E+121 was cast to int in %s on line %d int(9223372036854775807) + +Warning: non-representable float-string 1.0E+301 was cast to int in %s on line %d int(9223372036854775807) int(0) diff --git a/Zend/tests/type_coercion/float_to_int/explicit_casts_should_not_warn_32bit.phpt b/Zend/tests/type_coercion/float_to_int/explicit_casts_should_not_warn_32bit.phpt index fee011df06ea8..3a2ea01f26821 100644 --- a/Zend/tests/type_coercion/float_to_int/explicit_casts_should_not_warn_32bit.phpt +++ b/Zend/tests/type_coercion/float_to_int/explicit_casts_should_not_warn_32bit.phpt @@ -25,14 +25,24 @@ foreach($values as $value) { } ?> ---EXPECT-- +--EXPECTF-- int(3) int(3) + +Warning: non-representable float 1.0E+121 was cast to int in %s on line %d int(0) + +Warning: non-representable float 1.0E+301 was cast to int in %s on line %d int(0) + +Warning: non-representable float NAN was cast to int in %s on line %d int(0) int(3) int(3) + +Warning: non-representable float-string 1.0E+121 was cast to int in %s on line %d int(2147483647) + +Warning: non-representable float-string 1.0E+301 was cast to int in %s on line %d int(2147483647) int(0) diff --git a/Zend/tests/type_coercion/float_to_int/warning_float_does_not_fit_zend_long_arrays.phpt b/Zend/tests/type_coercion/float_to_int/warning_float_does_not_fit_zend_long_arrays.phpt index bb27d1bb49ddb..ba8daa39f9f63 100644 --- a/Zend/tests/type_coercion/float_to_int/warning_float_does_not_fit_zend_long_arrays.phpt +++ b/Zend/tests/type_coercion/float_to_int/warning_float_does_not_fit_zend_long_arrays.phpt @@ -23,12 +23,15 @@ var_dump($array[$string_float]); ?> --EXPECTF-- +Warning: non-representable float 1.0E+121 was cast to int in %s on line %d int(0) + +Warning: non-representable float-string 1.0E+121 was cast to int in %s on line %d bool(true) -Deprecated: Implicit conversion from float 1.0E+121 to int loses precision in %s on line %d +Warning: non-representable float 1.0E+121 was cast to int in %s on line %d -Deprecated: Implicit conversion from float 1.0E+121 to int loses precision in %s on line %d +Warning: non-representable float 1.0E+121 was cast to int in %s on line %d array(2) { [0]=> string(11) "Large float" @@ -42,13 +45,13 @@ array(2) { string(18) "String large float" } -Deprecated: Implicit conversion from float 1.0E+121 to int loses precision in %s on line %d +Warning: non-representable float 1.0E+121 was cast to int in %s on line %d string(1) "0" Warning: Undefined array key "1.0E+121" in %s on line %d NULL -Deprecated: Implicit conversion from float 1.0E+121 to int loses precision in %s on line %d +Warning: non-representable float 1.0E+121 was cast to int in %s on line %d string(1) "0" Warning: Undefined array key "1.0E+121" in %s on line %d diff --git a/Zend/tests/type_coercion/float_to_int/warning_float_does_not_fit_zend_long_strings.phpt b/Zend/tests/type_coercion/float_to_int/warning_float_does_not_fit_zend_long_strings.phpt index 0c63cba1f5bc0..1ba07baa1eaf4 100644 --- a/Zend/tests/type_coercion/float_to_int/warning_float_does_not_fit_zend_long_strings.phpt +++ b/Zend/tests/type_coercion/float_to_int/warning_float_does_not_fit_zend_long_strings.phpt @@ -75,7 +75,10 @@ var_dump($string); ?> --EXPECTF-- +Warning: non-representable float 1.0E+121 was cast to int in %s on line %d int(0) + +Warning: non-representable float-string 1.0E+121 was cast to int in %s on line %d int(9223372036854775807) Attempt to read Float diff --git a/Zend/tests/type_coercion/float_to_int/warning_float_does_not_fit_zend_long_strings_32bit.phpt b/Zend/tests/type_coercion/float_to_int/warning_float_does_not_fit_zend_long_strings_32bit.phpt index cf2e396c311ba..ed711b25d557b 100644 --- a/Zend/tests/type_coercion/float_to_int/warning_float_does_not_fit_zend_long_strings_32bit.phpt +++ b/Zend/tests/type_coercion/float_to_int/warning_float_does_not_fit_zend_long_strings_32bit.phpt @@ -75,7 +75,10 @@ var_dump($string); ?> --EXPECTF-- +Warning: non-representable float 1.0E+121 was cast to int in %s on line %d int(0) + +Warning: non-representable float-string 1.0E+121 was cast to int in %s on line %d int(2147483647) Attempt to read Float diff --git a/Zend/tests/type_coercion/int_special_values.phpt b/Zend/tests/type_coercion/int_special_values.phpt index eedb9ab2c02ac..76000662b7b9d 100644 --- a/Zend/tests/type_coercion/int_special_values.phpt +++ b/Zend/tests/type_coercion/int_special_values.phpt @@ -17,14 +17,18 @@ foreach($values as $value) { echo PHP_EOL; } ?> ---EXPECT-- +--EXPECTF-- float(0) int(0) float(INF) + +Warning: non-representable float INF was cast to int in %s on line %d int(0) float(-INF) + +Warning: non-representable float -INF was cast to int in %s on line %d int(0) float(0) @@ -34,4 +38,6 @@ float(-0) int(0) float(NAN) + +Warning: non-representable float NAN was cast to int in %s on line %d int(0) diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index ad735c41acaff..f8a5682da17dc 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -9939,14 +9939,14 @@ ZEND_API bool zend_is_op_long_compatible(const zval *op) } if (Z_TYPE_P(op) == IS_DOUBLE - && !zend_is_long_compatible(Z_DVAL_P(op), zend_dval_to_lval(Z_DVAL_P(op)))) { + && !zend_is_long_compatible(Z_DVAL_P(op), zend_dval_to_lval_silent(Z_DVAL_P(op)))) { return false; } if (Z_TYPE_P(op) == IS_STRING) { double dval = 0; uint8_t is_num = is_numeric_str_function(Z_STR_P(op), NULL, &dval); - if (is_num == 0 || (is_num == IS_DOUBLE && !zend_is_long_compatible(dval, zend_dval_to_lval(dval)))) { + if (is_num == 0 || (is_num == IS_DOUBLE && !zend_is_long_compatible(dval, zend_dval_to_lval_silent(dval)))) { return false; } } @@ -9995,11 +9995,23 @@ ZEND_API bool zend_binary_op_produces_error(uint32_t opcode, const zval *op1, co return 1; } - if ((opcode == ZEND_MOD && zval_get_long(op2) == 0) - || (opcode == ZEND_DIV && zval_get_double(op2) == 0.0)) { + /* Operation which cast float/float-strings to integers might produce incompatible float to int errors */ + if (opcode == ZEND_SL || opcode == ZEND_SR || opcode == ZEND_BW_OR + || opcode == ZEND_BW_AND || opcode == ZEND_BW_XOR) { + return !zend_is_op_long_compatible(op1) || !zend_is_op_long_compatible(op2); + } + + if (opcode == ZEND_DIV && zval_get_double(op2) == 0.0) { /* Division by zero throws an error. */ return 1; } + + /* Mod is an operation that will cast float/float-strings to integers which might + produce float to int incompatible errors, and also cannot be divided by 0 */ + if (opcode == ZEND_MOD) { + return !zend_is_op_long_compatible(op1) || !zend_is_op_long_compatible(op2) || zval_get_long(op2) == 0; + } + if ((opcode == ZEND_POW) && zval_get_double(op1) == 0 && zval_get_double(op2) < 0) { /* 0 ** (<0) throws a division by zero error. */ return 1; @@ -10009,12 +10021,6 @@ ZEND_API bool zend_binary_op_produces_error(uint32_t opcode, const zval *op1, co return 1; } - /* Operation which cast float/float-strings to integers might produce incompatible float to int errors */ - if (opcode == ZEND_SL || opcode == ZEND_SR || opcode == ZEND_BW_OR - || opcode == ZEND_BW_AND || opcode == ZEND_BW_XOR || opcode == ZEND_MOD) { - return !zend_is_op_long_compatible(op1) || !zend_is_op_long_compatible(op2); - } - return 0; } /* }}} */ @@ -10166,7 +10172,7 @@ static bool zend_try_ct_eval_array(zval *result, zend_ast *ast) /* {{{ */ zend_symtable_update(Z_ARRVAL_P(result), Z_STR_P(key), value); break; case IS_DOUBLE: { - zend_long lval = zend_dval_to_lval(Z_DVAL_P(key)); + zend_long lval = zend_dval_to_lval_silent(Z_DVAL_P(key)); /* Incompatible float will generate an error, leave this to run-time */ if (!zend_is_long_compatible(Z_DVAL_P(key), lval)) { zval_ptr_dtor_nogc(value); @@ -12057,6 +12063,9 @@ bool zend_try_ct_eval_cast(zval *result, uint32_t type, zval *op1) ZVAL_BOOL(result, zval_is_true(op1)); return true; case IS_LONG: + if (Z_TYPE_P(op1) == IS_DOUBLE && !ZEND_DOUBLE_FITS_LONG(Z_DVAL_P((op1)))) { + return false; + } ZVAL_LONG(result, zval_get_long(op1)); return true; case IS_DOUBLE: diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index 940c2f98b382f..353a75d816bbf 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -1732,10 +1732,13 @@ static zend_never_inline zend_long zend_check_string_offset(zval *dim, int type zend_illegal_string_offset(dim, type); return 0; } + case IS_DOUBLE: + /* Suppress potential double warning */ + zend_error(E_WARNING, "String offset cast occurred"); + return zend_dval_to_lval_silent(Z_DVAL_P(dim)); case IS_UNDEF: ZVAL_UNDEFINED_OP2(); ZEND_FALLTHROUGH; - case IS_DOUBLE: case IS_NULL: case IS_FALSE: case IS_TRUE: @@ -2668,21 +2671,18 @@ static zend_never_inline uint8_t slow_index_convert(HashTable *ht, const zval *d value->str = ZSTR_EMPTY_ALLOC(); return IS_STRING; case IS_DOUBLE: - value->lval = zend_dval_to_lval(Z_DVAL_P(dim)); - if (!zend_is_long_compatible(Z_DVAL_P(dim), value->lval)) { - /* The array may be destroyed while throwing the notice. - * Temporarily increase the refcount to detect this situation. */ - if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) { - GC_ADDREF(ht); - } - zend_incompatible_double_to_long_error(Z_DVAL_P(dim)); - if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) { - zend_array_destroy(ht); - return IS_NULL; - } - if (EG(exception)) { - return IS_NULL; - } + /* The array may be destroyed while throwing the notice. + * Temporarily increase the refcount to detect this situation. */ + if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) { + GC_ADDREF(ht); + } + value->lval = zend_dval_to_lval_safe(Z_DVAL_P(dim)); + if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) { + zend_array_destroy(ht); + return IS_NULL; + } + if (EG(exception)) { + return IS_NULL; } return IS_LONG; case IS_RESOURCE: @@ -2753,23 +2753,20 @@ static zend_never_inline uint8_t slow_index_convert_w(HashTable *ht, const zval value->str = ZSTR_EMPTY_ALLOC(); return IS_STRING; case IS_DOUBLE: - value->lval = zend_dval_to_lval(Z_DVAL_P(dim)); - if (!zend_is_long_compatible(Z_DVAL_P(dim), value->lval)) { - /* The array may be destroyed while throwing the notice. - * Temporarily increase the refcount to detect this situation. */ - if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) { - GC_ADDREF(ht); - } - zend_incompatible_double_to_long_error(Z_DVAL_P(dim)); - if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && GC_DELREF(ht) != 1) { - if (!GC_REFCOUNT(ht)) { - zend_array_destroy(ht); - } - return IS_NULL; - } - if (EG(exception)) { - return IS_NULL; + /* The array may be destroyed while throwing the notice. + * Temporarily increase the refcount to detect this situation. */ + if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) { + GC_ADDREF(ht); + } + value->lval = zend_dval_to_lval_safe(Z_DVAL_P(dim)); + if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && GC_DELREF(ht) != 1) { + if (!GC_REFCOUNT(ht)) { + zend_array_destroy(ht); } + return IS_NULL; + } + if (EG(exception)) { + return IS_NULL; } return IS_LONG; case IS_RESOURCE: @@ -3129,6 +3126,11 @@ static zend_always_inline void zend_fetch_dimension_address_read(zval *result, z return; } } + /* To prevent double warning */ + if (Z_TYPE_P(dim) == IS_DOUBLE) { + offset = zend_dval_to_lval_silent(Z_DVAL_P(dim)); + goto out; + } break; case IS_REFERENCE: dim = Z_REFVAL_P(dim); diff --git a/Zend/zend_operators.c b/Zend/zend_operators.c index e6e0c82c79f20..5ea5cb61593fe 100644 --- a/Zend/zend_operators.c +++ b/Zend/zend_operators.c @@ -387,12 +387,9 @@ static zend_never_inline zend_long ZEND_FASTCALL zendi_try_get_long(const zval * return 1; case IS_DOUBLE: { double dval = Z_DVAL_P(op); - zend_long lval = zend_dval_to_lval(dval); - if (!zend_is_long_compatible(dval, lval)) { - zend_incompatible_double_to_long_error(dval); - if (UNEXPECTED(EG(exception))) { - *failed = 1; - } + zend_long lval = zend_dval_to_lval_safe(dval); + if (UNEXPECTED(EG(exception))) { + *failed = 1; } return lval; } @@ -911,6 +908,14 @@ 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_oob_double_to_long_error(double d) +{ + zend_error_unchecked(E_WARNING, "non-representable float %.*H was cast to int", -1, d); +} +ZEND_API void ZEND_COLD zend_oob_string_to_long_error(double d) +{ + zend_error_unchecked(E_WARNING, "non-representable float-string %.*H was cast to int", -1, d); +} ZEND_API zend_long ZEND_FASTCALL zval_get_long_func(const zval *op, bool is_strict) /* {{{ */ { @@ -1613,15 +1618,12 @@ ZEND_API zend_result ZEND_FASTCALL bitwise_not_function(zval *result, zval *op1) ZVAL_LONG(result, ~Z_LVAL_P(op1)); return SUCCESS; case IS_DOUBLE: { - zend_long lval = zend_dval_to_lval(Z_DVAL_P(op1)); - if (!zend_is_long_compatible(Z_DVAL_P(op1), lval)) { - zend_incompatible_double_to_long_error(Z_DVAL_P(op1)); - if (EG(exception)) { - if (result != op1) { - ZVAL_UNDEF(result); - } - return FAILURE; + zend_long lval = zend_dval_to_lval_safe(Z_DVAL_P(op1)); + if (EG(exception)) { + if (result != op1) { + ZVAL_UNDEF(result); } + return FAILURE; } ZVAL_LONG(result, ~lval); return SUCCESS; diff --git a/Zend/zend_operators.h b/Zend/zend_operators.h index 63b0fb62e49f2..ef48014684a5b 100644 --- a/Zend/zend_operators.h +++ b/Zend/zend_operators.h @@ -115,11 +115,28 @@ ZEND_API const char* ZEND_FASTCALL zend_memnrstr_ex(const char *haystack, const # define ZEND_DOUBLE_FITS_LONG(d) (!((d) >= (double)ZEND_LONG_MAX || (d) < (double)ZEND_LONG_MIN)) #endif +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_COLD zend_oob_double_to_long_error(double d); +ZEND_API void ZEND_COLD zend_oob_string_to_long_error(double d); + ZEND_API zend_long ZEND_FASTCALL zend_dval_to_lval_slow(double d); static zend_always_inline zend_long zend_dval_to_lval(double d) { - if (UNEXPECTED(!zend_finite(d)) || UNEXPECTED(zend_isnan(d))) { + if (UNEXPECTED(!zend_finite(d))) { + zend_oob_double_to_long_error(d); + return 0; + } else if (!ZEND_DOUBLE_FITS_LONG(d)) { + zend_oob_double_to_long_error(d); + return zend_dval_to_lval_slow(d); + } + return (zend_long)d; +} + +static zend_always_inline zend_long zend_dval_to_lval_silent(double d) +{ + if (UNEXPECTED(!zend_finite(d))) { return 0; } else if (!ZEND_DOUBLE_FITS_LONG(d)) { return zend_dval_to_lval_slow(d); @@ -130,9 +147,11 @@ static zend_always_inline zend_long zend_dval_to_lval(double d) /* Used to convert a string float to integer during an (int) cast */ static zend_always_inline zend_long zend_dval_to_lval_cap(double d) { - if (UNEXPECTED(!zend_finite(d)) || UNEXPECTED(zend_isnan(d))) { + if (UNEXPECTED(!zend_finite(d))) { + zend_oob_string_to_long_error(d); return 0; } else if (!ZEND_DOUBLE_FITS_LONG(d)) { + zend_oob_string_to_long_error(d); return (d > 0 ? ZEND_LONG_MAX : ZEND_LONG_MIN); } return (zend_long)d; @@ -143,13 +162,10 @@ static zend_always_inline bool zend_is_long_compatible(double d, zend_long l) { return (double)l == d; } -ZEND_API void zend_incompatible_double_to_long_error(double d); -ZEND_API void zend_incompatible_string_to_long_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); - if (!zend_is_long_compatible(d, l)) { + if (!zend_is_long_compatible(d, l) && ZEND_DOUBLE_FITS_LONG(d)) { zend_incompatible_double_to_long_error(d); } return l; diff --git a/ext/date/tests/bug79015.phpt b/ext/date/tests/bug79015.phpt index 99cb03f75d5cb..a68014c6ca76b 100644 --- a/ext/date/tests/bug79015.phpt +++ b/ext/date/tests/bug79015.phpt @@ -6,6 +6,7 @@ $payload = 'O:12:"DateInterval":9:{s:1:"y";i:1;s:1:"m";i:0;s:1:"d";i:4;s:1:"h";i var_dump(unserialize($payload)); ?> --EXPECTF-- +Warning: non-representable float 9.99999999999E+18 was cast to int in %s on line %d object(DateInterval)#%d (%d) { ["y"]=> int(1) diff --git a/ext/intl/tests/gh13766.phpt b/ext/intl/tests/gh13766.phpt index 70567fa860537..4d164b9465fe3 100644 --- a/ext/intl/tests/gh13766.phpt +++ b/ext/intl/tests/gh13766.phpt @@ -32,4 +32,4 @@ int(%d) string(19) "America/Los_Angeles" IntlDateFormatter::parseToCalendar(): Argument #2 ($offset) must be of type int, string given -Deprecated: Implicit conversion from float %r(1\.4757395258967641E\+20|34359738352)%r to int loses precision in %s on line %d +Warning: non-representable float %r(1\.4757395258967641E\+20|34359738352)%r was cast to int in %s on line %d diff --git a/ext/opcache/jit/zend_jit_helpers.c b/ext/opcache/jit/zend_jit_helpers.c index ce48d10223412..04fbe15a26d5b 100644 --- a/ext/opcache/jit/zend_jit_helpers.c +++ b/ext/opcache/jit/zend_jit_helpers.c @@ -513,33 +513,30 @@ static void ZEND_FASTCALL zend_jit_fetch_dim_r_helper(zend_array *ht, zval *dim, } return; case IS_DOUBLE: - hval = zend_dval_to_lval(Z_DVAL_P(dim)); - if (!zend_is_long_compatible(Z_DVAL_P(dim), hval)) { - /* The array may be destroyed while throwing the notice. - * Temporarily increase the refcount to detect this situation. */ - if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) { - GC_ADDREF(ht); - } - execute_data = EG(current_execute_data); - opline = EX(opline); - zend_incompatible_double_to_long_error(Z_DVAL_P(dim)); - if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) { - zend_array_destroy(ht); - if (opline->result_type & (IS_VAR | IS_TMP_VAR)) { - if (EG(exception)) { - ZVAL_UNDEF(EX_VAR(opline->result.var)); - } else { - ZVAL_NULL(EX_VAR(opline->result.var)); - } - } - return; - } - if (EG(exception)) { - if (opline->result_type & (IS_VAR | IS_TMP_VAR)) { + /* The array may be destroyed while throwing the notice. + * Temporarily increase the refcount to detect this situation. */ + if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) { + GC_ADDREF(ht); + } + execute_data = EG(current_execute_data); + opline = EX(opline); + hval = zend_dval_to_lval_safe(Z_DVAL_P(dim)); + if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) { + zend_array_destroy(ht); + if (opline->result_type & (IS_VAR | IS_TMP_VAR)) { + if (EG(exception)) { ZVAL_UNDEF(EX_VAR(opline->result.var)); + } else { + ZVAL_NULL(EX_VAR(opline->result.var)); } - return; } + return; + } + if (EG(exception)) { + if (opline->result_type & (IS_VAR | IS_TMP_VAR)) { + ZVAL_UNDEF(EX_VAR(opline->result.var)); + } + return; } goto num_index; case IS_RESOURCE: @@ -663,33 +660,30 @@ static void ZEND_FASTCALL zend_jit_fetch_dim_is_helper(zend_array *ht, zval *dim return; case IS_DOUBLE: - hval = zend_dval_to_lval(Z_DVAL_P(dim)); - if (!zend_is_long_compatible(Z_DVAL_P(dim), hval)) { - /* The array may be destroyed while throwing the notice. - * Temporarily increase the refcount to detect this situation. */ - if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) { - GC_ADDREF(ht); - } - execute_data = EG(current_execute_data); - opline = EX(opline); - zend_incompatible_double_to_long_error(Z_DVAL_P(dim)); - if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) { - zend_array_destroy(ht); - if (opline->result_type & (IS_VAR | IS_TMP_VAR)) { - if (EG(exception)) { - ZVAL_UNDEF(EX_VAR(opline->result.var)); - } else { - ZVAL_NULL(EX_VAR(opline->result.var)); - } - } - return; - } - if (EG(exception)) { - if (opline->result_type & (IS_VAR | IS_TMP_VAR)) { + /* The array may be destroyed while throwing the notice. + * Temporarily increase the refcount to detect this situation. */ + if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) { + GC_ADDREF(ht); + } + execute_data = EG(current_execute_data); + opline = EX(opline); + hval = zend_dval_to_lval_safe(Z_DVAL_P(dim)); + if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) { + zend_array_destroy(ht); + if (opline->result_type & (IS_VAR | IS_TMP_VAR)) { + if (EG(exception)) { ZVAL_UNDEF(EX_VAR(opline->result.var)); + } else { + ZVAL_NULL(EX_VAR(opline->result.var)); } - return; } + return; + } + if (EG(exception)) { + if (opline->result_type & (IS_VAR | IS_TMP_VAR)) { + ZVAL_UNDEF(EX_VAR(opline->result.var)); + } + return; } goto num_index; case IS_RESOURCE: @@ -799,21 +793,18 @@ static int ZEND_FASTCALL zend_jit_fetch_dim_isset_helper(zend_array *ht, zval *d return result; } case IS_DOUBLE: - hval = zend_dval_to_lval(Z_DVAL_P(dim)); - if (!zend_is_long_compatible(Z_DVAL_P(dim), hval)) { - /* The array may be destroyed while throwing the notice. - * Temporarily increase the refcount to detect this situation. */ - if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) { - GC_ADDREF(ht); - } - zend_incompatible_double_to_long_error(Z_DVAL_P(dim)); - if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) { - zend_array_destroy(ht); - return 0; - } - if (EG(exception)) { - return 0; - } + /* The array may be destroyed while throwing the notice. + * Temporarily increase the refcount to detect this situation. */ + if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) { + GC_ADDREF(ht); + } + hval = zend_dval_to_lval_safe(Z_DVAL_P(dim)); + if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) { + zend_array_destroy(ht); + return 0; + } + if (EG(exception)) { + return 0; } goto num_index; case IS_RESOURCE: @@ -933,35 +924,32 @@ static zval* ZEND_FASTCALL zend_jit_fetch_dim_rw_helper(zend_array *ht, zval *di offset_key = ZSTR_EMPTY_ALLOC(); goto str_index; case IS_DOUBLE: - hval = zend_dval_to_lval(Z_DVAL_P(dim)); - if (!zend_is_long_compatible(Z_DVAL_P(dim), hval)) { - /* The array may be destroyed while throwing the notice. - * Temporarily increase the refcount to detect this situation. */ - if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) { - GC_ADDREF(ht); - } - execute_data = EG(current_execute_data); - opline = EX(opline); - zend_incompatible_double_to_long_error(Z_DVAL_P(dim)); - if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && GC_DELREF(ht) != 1) { - if (!GC_REFCOUNT(ht)) { - zend_array_destroy(ht); - } - if (opline->result_type & (IS_VAR | IS_TMP_VAR)) { - if (EG(exception)) { - ZVAL_UNDEF(EX_VAR(opline->result.var)); - } else { - ZVAL_NULL(EX_VAR(opline->result.var)); - } - } - return NULL; + /* The array may be destroyed while throwing the notice. + * Temporarily increase the refcount to detect this situation. */ + if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) { + GC_ADDREF(ht); + } + execute_data = EG(current_execute_data); + opline = EX(opline); + hval = zend_dval_to_lval_safe(Z_DVAL_P(dim)); + if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && GC_DELREF(ht) != 1) { + if (!GC_REFCOUNT(ht)) { + zend_array_destroy(ht); } - if (EG(exception)) { - if (opline->result_type & (IS_VAR | IS_TMP_VAR)) { + if (opline->result_type & (IS_VAR | IS_TMP_VAR)) { + if (EG(exception)) { ZVAL_UNDEF(EX_VAR(opline->result.var)); + } else { + ZVAL_NULL(EX_VAR(opline->result.var)); } - return NULL; } + return NULL; + } + if (EG(exception)) { + if (opline->result_type & (IS_VAR | IS_TMP_VAR)) { + ZVAL_UNDEF(EX_VAR(opline->result.var)); + } + return NULL; } goto num_index; case IS_RESOURCE: @@ -1096,35 +1084,32 @@ static zval* ZEND_FASTCALL zend_jit_fetch_dim_w_helper(zend_array *ht, zval *dim offset_key = ZSTR_EMPTY_ALLOC(); goto str_index; case IS_DOUBLE: - hval = zend_dval_to_lval(Z_DVAL_P(dim)); - if (!zend_is_long_compatible(Z_DVAL_P(dim), hval)) { - /* The array may be destroyed while throwing the notice. - * Temporarily increase the refcount to detect this situation. */ - if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) { - GC_ADDREF(ht); - } - execute_data = EG(current_execute_data); - opline = EX(opline); - zend_incompatible_double_to_long_error(Z_DVAL_P(dim)); - if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && GC_DELREF(ht) != 1) { - if (!GC_REFCOUNT(ht)) { - zend_array_destroy(ht); - } - if (opline->result_type & (IS_VAR | IS_TMP_VAR)) { - if (EG(exception)) { - ZVAL_UNDEF(EX_VAR(opline->result.var)); - } else { - ZVAL_NULL(EX_VAR(opline->result.var)); - } - } - return NULL; + /* The array may be destroyed while throwing the notice. + * Temporarily increase the refcount to detect this situation. */ + if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) { + GC_ADDREF(ht); + } + execute_data = EG(current_execute_data); + opline = EX(opline); + hval = zend_dval_to_lval_safe(Z_DVAL_P(dim)); + if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && GC_DELREF(ht) != 1) { + if (!GC_REFCOUNT(ht)) { + zend_array_destroy(ht); } - if (EG(exception)) { - if (opline->result_type & (IS_VAR | IS_TMP_VAR)) { + if (opline->result_type & (IS_VAR | IS_TMP_VAR)) { + if (EG(exception)) { ZVAL_UNDEF(EX_VAR(opline->result.var)); + } else { + ZVAL_NULL(EX_VAR(opline->result.var)); } - return NULL; } + return NULL; + } + if (EG(exception)) { + if (opline->result_type & (IS_VAR | IS_TMP_VAR)) { + ZVAL_UNDEF(EX_VAR(opline->result.var)); + } + return NULL; } goto num_index; case IS_RESOURCE: @@ -1211,10 +1196,13 @@ static zend_never_inline zend_long zend_check_string_offset(zval *dim, int type) zend_illegal_container_offset(ZSTR_KNOWN(ZEND_STR_STRING), dim, BP_VAR_R); return 0; } + case IS_DOUBLE: + /* Suppress potential double warning */ + zend_error(E_WARNING, "String offset cast occurred"); + return zend_dval_to_lval_silent(Z_DVAL_P(dim)); case IS_UNDEF: zend_jit_undefined_op_helper(EG(current_execute_data)->opline->op2.var); ZEND_FALLTHROUGH; - case IS_DOUBLE: case IS_NULL: case IS_FALSE: case IS_TRUE: diff --git a/ext/opcache/tests/jit/add_011.phpt b/ext/opcache/tests/jit/add_011.phpt index 28c598c5540a0..5812f926961ee 100644 --- a/ext/opcache/tests/jit/add_011.phpt +++ b/ext/opcache/tests/jit/add_011.phpt @@ -195,5 +195,6 @@ int(-9223371969208523780) Warning: Undefined variable $u in %sadd_011.php on line 5 -Deprecated: Implicit conversion from float %f to int loses precision in %sadd_011.php on line 5 -int(66572500992) \ No newline at end of file +Warning: non-representable float %f was cast to int in %sadd_011.php on line 5 +int(66572500992) + diff --git a/ext/opcache/tests/jit/array_elem_002.phpt b/ext/opcache/tests/jit/array_elem_002.phpt index 250f54349051b..d3d2732f0d4d8 100644 --- a/ext/opcache/tests/jit/array_elem_002.phpt +++ b/ext/opcache/tests/jit/array_elem_002.phpt @@ -11,7 +11,7 @@ $string_float= PHP_INT_MAX; $a = [$float => 'a', $string_float => 'b', 'c', 'd']; ?> --EXPECTF-- -Deprecated: Implicit conversion from float 1.0E+38 to int loses precision in %sarray_elem_002.php on line 4 +Warning: non-representable float 1.0E+38 was cast to int in %sarray_elem_002.php on line 4 Fatal error: Uncaught Error: Cannot add element to the array as the next element is already occupied in %sarray_elem_002.php:4 Stack trace: diff --git a/ext/opcache/tests/jit/gh19669-001.phpt b/ext/opcache/tests/jit/gh19669-001.phpt index 7d63643bb0157..af92eb3f4f66f 100644 --- a/ext/opcache/tests/jit/gh19669-001.phpt +++ b/ext/opcache/tests/jit/gh19669-001.phpt @@ -20,5 +20,6 @@ function test() { } var_dump(test()); ?> ---EXPECT-- +--EXPECTF-- +Warning: non-representable float -1.8446744073709552E+19 was cast to int in %s on line %d int(-3) diff --git a/ext/opcache/tests/jit/gh19669-002.phpt b/ext/opcache/tests/jit/gh19669-002.phpt index 373356bcd0612..0465420b2fd64 100644 --- a/ext/opcache/tests/jit/gh19669-002.phpt +++ b/ext/opcache/tests/jit/gh19669-002.phpt @@ -20,5 +20,6 @@ function test() { } var_dump(test()); ?> ---EXPECT-- +--EXPECTF-- +Warning: non-representable float -1.8446744073709552E+19 was cast to int in %s on line %d int(-10) diff --git a/ext/opcache/tests/jit/reg_alloc_003_32bits.phpt b/ext/opcache/tests/jit/reg_alloc_003_32bits.phpt index 9b373c6230852..aaca14518ffd3 100644 --- a/ext/opcache/tests/jit/reg_alloc_003_32bits.phpt +++ b/ext/opcache/tests/jit/reg_alloc_003_32bits.phpt @@ -23,5 +23,5 @@ function test($char_code) { echo test(65), "\n"; ?> --EXPECTF-- -Deprecated: Implicit conversion from float 4294967168 to int loses precision in %s on line %d +Warning: non-representable float 4294967168 was cast to int in %s on line %d correct diff --git a/ext/openssl/tests/openssl_decrypt_basic.phpt b/ext/openssl/tests/openssl_decrypt_basic.phpt index 6cb2297a979b1..0f674dbc1e348 100644 --- a/ext/openssl/tests/openssl_decrypt_basic.phpt +++ b/ext/openssl/tests/openssl_decrypt_basic.phpt @@ -10,8 +10,7 @@ $password = "openssl"; $ivlen = openssl_cipher_iv_length($method); $iv = ''; -srand(time() + ((int)(microtime(true) * 1000000) % 1000000)); -while(strlen($iv) < $ivlen) $iv .= chr(rand(0,255)); +while(strlen($iv) < $ivlen) $iv .= random_bytes(1); $encrypted = openssl_encrypt($data, $method, $password, 0, $iv); $output = openssl_decrypt($encrypted, $method, $password, 0, $iv); diff --git a/ext/standard/array.c b/ext/standard/array.c index 96795e623cb9e..be9702c5ef650 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -1219,7 +1219,7 @@ PHP_FUNCTION(min) min_lval = Z_LVAL(args[i]); min = &args[i]; } - } else if (Z_TYPE(args[i]) == IS_DOUBLE && (zend_dval_to_lval((double) min_lval) == min_lval)) { + } else if (Z_TYPE(args[i]) == IS_DOUBLE && (zend_dval_to_lval_silent((double) min_lval) == min_lval)) { /* if min_lval can be exactly represented as a double, go to double dedicated code */ min_dval = (double) min_lval; goto double_compare; @@ -1239,7 +1239,7 @@ PHP_FUNCTION(min) min_dval = Z_DVAL(args[i]); min = &args[i]; } - } else if (Z_TYPE(args[i]) == IS_LONG && (zend_dval_to_lval((double) Z_LVAL(args[i])) == Z_LVAL(args[i]))) { + } else if (Z_TYPE(args[i]) == IS_LONG && (zend_dval_to_lval_silent((double) Z_LVAL(args[i])) == Z_LVAL(args[i]))) { /* if the value can be exactly represented as a double, use double dedicated code otherwise generic */ if (min_dval > (double)Z_LVAL(args[i])) { min_dval = (double)Z_LVAL(args[i]); @@ -1277,7 +1277,7 @@ ZEND_FRAMELESS_FUNCTION(min, 2) if (EXPECTED(Z_TYPE_P(rhs) == IS_LONG)) { RETURN_COPY_VALUE(lhs_lval < Z_LVAL_P(rhs) ? lhs : rhs); - } else if (Z_TYPE_P(rhs) == IS_DOUBLE && (zend_dval_to_lval((double) lhs_lval) == lhs_lval)) { + } else if (Z_TYPE_P(rhs) == IS_DOUBLE && (zend_dval_to_lval_silent((double) lhs_lval) == lhs_lval)) { /* if lhs_lval can be exactly represented as a double, go to double dedicated code */ lhs_dval = (double) lhs_lval; goto double_compare; @@ -1290,7 +1290,7 @@ ZEND_FRAMELESS_FUNCTION(min, 2) if (EXPECTED(Z_TYPE_P(rhs) == IS_DOUBLE)) { double_compare: RETURN_COPY_VALUE(lhs_dval < Z_DVAL_P(rhs) ? lhs : rhs); - } else if (Z_TYPE_P(rhs) == IS_LONG && (zend_dval_to_lval((double) Z_LVAL_P(rhs)) == Z_LVAL_P(rhs))) { + } else if (Z_TYPE_P(rhs) == IS_LONG && (zend_dval_to_lval_silent((double) Z_LVAL_P(rhs)) == Z_LVAL_P(rhs))) { /* if the value can be exactly represented as a double, use double dedicated code otherwise generic */ RETURN_COPY_VALUE(lhs_dval < (double)Z_LVAL_P(rhs) ? lhs : rhs); } else { @@ -1347,7 +1347,7 @@ PHP_FUNCTION(max) max_lval = Z_LVAL(args[i]); max = &args[i]; } - } else if (Z_TYPE(args[i]) == IS_DOUBLE && (zend_dval_to_lval((double) max_lval) == max_lval)) { + } else if (Z_TYPE(args[i]) == IS_DOUBLE && (zend_dval_to_lval_silent((double) max_lval) == max_lval)) { /* if max_lval can be exactly represented as a double, go to double dedicated code */ max_dval = (double) max_lval; goto double_compare; @@ -1367,7 +1367,7 @@ PHP_FUNCTION(max) max_dval = Z_DVAL(args[i]); max = &args[i]; } - } else if (Z_TYPE(args[i]) == IS_LONG && (zend_dval_to_lval((double) Z_LVAL(args[i])) == Z_LVAL(args[i]))) { + } else if (Z_TYPE(args[i]) == IS_LONG && (zend_dval_to_lval_silent((double) Z_LVAL(args[i])) == Z_LVAL(args[i]))) { /* if the value can be exactly represented as a double, use double dedicated code otherwise generic */ if (max_dval < (double)Z_LVAL(args[i])) { max_dval = (double)Z_LVAL(args[i]); @@ -1405,7 +1405,7 @@ ZEND_FRAMELESS_FUNCTION(max, 2) if (EXPECTED(Z_TYPE_P(rhs) == IS_LONG)) { RETURN_COPY_VALUE(lhs_lval >= Z_LVAL_P(rhs) ? lhs : rhs); - } else if (Z_TYPE_P(rhs) == IS_DOUBLE && (zend_dval_to_lval((double) lhs_lval) == lhs_lval)) { + } else if (Z_TYPE_P(rhs) == IS_DOUBLE && (zend_dval_to_lval_silent((double) lhs_lval) == lhs_lval)) { /* if lhs_lval can be exactly represented as a double, go to double dedicated code */ lhs_dval = (double) lhs_lval; goto double_compare; @@ -1418,7 +1418,7 @@ ZEND_FRAMELESS_FUNCTION(max, 2) if (EXPECTED(Z_TYPE_P(rhs) == IS_DOUBLE)) { double_compare: RETURN_COPY_VALUE(lhs_dval >= Z_DVAL_P(rhs) ? lhs : rhs); - } else if (Z_TYPE_P(rhs) == IS_LONG && (zend_dval_to_lval((double) Z_LVAL_P(rhs)) == Z_LVAL_P(rhs))) { + } else if (Z_TYPE_P(rhs) == IS_LONG && (zend_dval_to_lval_silent((double) Z_LVAL_P(rhs)) == Z_LVAL_P(rhs))) { /* if the value can be exactly represented as a double, use double dedicated code otherwise generic */ RETURN_COPY_VALUE(lhs_dval >= (double)Z_LVAL_P(rhs) ? lhs : rhs); } else { @@ -2980,7 +2980,7 @@ PHP_FUNCTION(range) is_step_negative = true; step_double *= -1; } - step = zend_dval_to_lval(step_double); + step = zend_dval_to_lval_silent(step_double); if (!zend_is_long_compatible(step_double, step)) { is_step_double = true; } diff --git a/ext/standard/tests/general_functions/gettype_settype_variation2.phpt b/ext/standard/tests/general_functions/gettype_settype_variation2.phpt index 12f001e924e46..25152e8288c34 100644 --- a/ext/standard/tests/general_functions/gettype_settype_variation2.phpt +++ b/ext/standard/tests/general_functions/gettype_settype_variation2.phpt @@ -274,6 +274,7 @@ int(1) string(7) "integer" -- Iteration 20 -- string(6) "string" +2: non-representable float-string 2.974394749328742E+21 was cast to int bool(true) int(2147483647) string(7) "integer" @@ -304,6 +305,7 @@ int(1) string(7) "integer" -- Iteration 26 -- string(6) "string" +2: non-representable float-string 2.974394749328742E+21 was cast to int bool(true) int(2147483647) string(7) "integer" @@ -424,11 +426,13 @@ int(2147483647) string(7) "integer" -- Iteration 50 -- string(6) "double" +2: non-representable float 2147483649 was cast to int bool(true) int(-2147483647) string(7) "integer" -- Iteration 51 -- string(6) "double" +2: non-representable float 1232147483649 was cast to int bool(true) int(-508130303) string(7) "integer" @@ -439,6 +443,7 @@ int(85) string(7) "integer" -- Iteration 53 -- string(6) "double" +2: non-representable float 1058513956921 was cast to int bool(true) int(1952002105) string(7) "integer" @@ -459,6 +464,7 @@ int(-365) string(7) "integer" -- Iteration 57 -- string(6) "double" +2: non-representable float 80561044571754 was cast to int bool(true) int(343000682) string(7) "integer" @@ -669,6 +675,7 @@ int(1) string(7) "integer" -- Iteration 20 -- string(6) "string" +2: non-representable float-string 2.974394749328742E+21 was cast to int bool(true) int(2147483647) string(7) "integer" @@ -699,6 +706,7 @@ int(1) string(7) "integer" -- Iteration 26 -- string(6) "string" +2: non-representable float-string 2.974394749328742E+21 was cast to int bool(true) int(2147483647) string(7) "integer" @@ -819,11 +827,13 @@ int(2147483647) string(7) "integer" -- Iteration 50 -- string(6) "double" +2: non-representable float 2147483649 was cast to int bool(true) int(-2147483647) string(7) "integer" -- Iteration 51 -- string(6) "double" +2: non-representable float 1232147483649 was cast to int bool(true) int(-508130303) string(7) "integer" @@ -834,6 +844,7 @@ int(85) string(7) "integer" -- Iteration 53 -- string(6) "double" +2: non-representable float 1058513956921 was cast to int bool(true) int(1952002105) string(7) "integer" @@ -854,6 +865,7 @@ int(-365) string(7) "integer" -- Iteration 57 -- string(6) "double" +2: non-representable float 80561044571754 was cast to int bool(true) int(343000682) string(7) "integer" diff --git a/ext/standard/tests/general_functions/intval.phpt b/ext/standard/tests/general_functions/intval.phpt index 51d3b128f4797..1a2549c115ffe 100644 --- a/ext/standard/tests/general_functions/intval.phpt +++ b/ext/standard/tests/general_functions/intval.phpt @@ -94,13 +94,10 @@ $not_int_types = array ( array(), array(0), array(1), - array(NULL), array(null), array("string"), array(true), - array(TRUE), array(false), - array(FALSE), array(1,2,3,4), array(1 => "One", "two" => 2), @@ -127,12 +124,6 @@ $not_int_types = array ( /* booleans */ true, false, - TRUE, - FALSE, - - /* undefined and unset vars */ - @$unset_var, - @$undefined_var ); @@ -230,11 +221,19 @@ int(-2147483648) int(2147483647) *** Testing intval() on non integer types *** + +Warning: non-representable float-string -2147483649 was cast to int in %s on line %d int(-2147483648) + +Warning: non-representable float-string 2147483648 was cast to int in %s on line %d int(2147483647) int(0) int(0) + +Warning: non-representable float-string 20000000001 was cast to int in %s on line %d int(2147483647) + +Warning: non-representable float-string -20000000001 was cast to int in %s on line %d int(-2147483648) int(0) int(0) @@ -256,9 +255,6 @@ int(1) int(1) int(1) int(1) -int(1) -int(1) -int(1) int(0) int(0) int(0) @@ -279,9 +275,5 @@ int(0) int(0) int(1) int(0) -int(1) -int(0) -int(0) -int(0) --- Done --- diff --git a/ext/standard/tests/math/bug30695.phpt b/ext/standard/tests/math/bug30695.phpt index 82771d0e0ab92..71bc39bdc316e 100644 --- a/ext/standard/tests/math/bug30695.phpt +++ b/ext/standard/tests/math/bug30695.phpt @@ -53,22 +53,22 @@ if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only"); echo "\n", toUTF8(65), "\n", toUTF8(233), "\n", toUTF8(1252), "\n", toUTF8(20095), "\n"; ?> --EXPECTF-- -Deprecated: Implicit conversion from float 4294967168 to int loses precision in %s on line %d +Warning: non-representable float 4294967168 was cast to int in %s on line %d A -Deprecated: Implicit conversion from float 4294967168 to int loses precision in %s on line %d +Warning: non-representable float 4294967168 was cast to int in %s on line %d -Deprecated: Implicit conversion from float 4294965248 to int loses precision in %s on line %d +Warning: non-representable float 4294965248 was cast to int in %s on line %d é -Deprecated: Implicit conversion from float 4294967168 to int loses precision in %s on line %d +Warning: non-representable float 4294967168 was cast to int in %s on line %d -Deprecated: Implicit conversion from float 4294965248 to int loses precision in %s on line %d +Warning: non-representable float 4294965248 was cast to int in %s on line %d Ӥ -Deprecated: Implicit conversion from float 4294967168 to int loses precision in %s on line %d +Warning: non-representable float 4294967168 was cast to int in %s on line %d -Deprecated: Implicit conversion from float 4294965248 to int loses precision in %s on line %d +Warning: non-representable float 4294965248 was cast to int in %s on line %d -Deprecated: Implicit conversion from float 4294901760 to int loses precision in %s on line %d +Warning: non-representable float 4294901760 was cast to int in %s on line %d 乿 diff --git a/ext/standard/tests/strings/bug47842.phpt b/ext/standard/tests/strings/bug47842.phpt index fe97308ea53a7..22b62560bc433 100644 --- a/ext/standard/tests/strings/bug47842.phpt +++ b/ext/standard/tests/strings/bug47842.phpt @@ -23,12 +23,14 @@ printf("printf 64-bit signed int '18446744073709551615' (2^64)-1 = %u\n", 184467 echo "Done\n"; ?> ---EXPECT-- +--EXPECTF-- -Test sscanf 32-bit signed int '2147483647' (2^31)-1 = 2147483647 sscanf 32-bit unsign int '4294967295' (2^32)-1 = 4294967295 sscanf 64-bit signed int '9223372036854775807' (2^63)-1 = 9223372036854775807 sscanf 64-bit unsign int '18446744073709551615' (2^64)-1 = 18446744073709551615 printf 64-bit signed int '9223372036854775807' (2^63)-1 = 9223372036854775807 + +Warning: non-representable float 1.8446744073709552E+19 was cast to int in %s on line %d printf 64-bit signed int '18446744073709551615' (2^64)-1 = 0 Done diff --git a/ext/standard/tests/strings/pack.phpt b/ext/standard/tests/strings/pack.phpt index af449266671da..643f023509cc4 100644 --- a/ext/standard/tests/strings/pack.phpt +++ b/ext/standard/tests/strings/pack.phpt @@ -97,7 +97,7 @@ print_r(unpack("v", pack("v", -1000))); print_r(unpack("v", pack("v", -64434))); print_r(unpack("v", pack("v", -65535))); ?> ---EXPECT-- +--EXPECTF-- Array ( [1] => h @@ -143,10 +143,14 @@ Array ( [1] => -64434 ) + +Warning: non-representable float 4294967296 was cast to int in %s on line %d Array ( [1] => 0 ) + +Warning: non-representable float -4294967296 was cast to int in %s on line %d Array ( [1] => 0 @@ -159,10 +163,14 @@ Array ( [1] => 0 ) + +Warning: non-representable float 2147483650 was cast to int in %s on line %d Array ( [1] => -2147483646 ) + +Warning: non-representable float 4294967295 was cast to int in %s on line %d Array ( [1] => -1 @@ -179,10 +187,14 @@ Array ( [1] => 0 ) + +Warning: non-representable float 2147483650 was cast to int in %s on line %d Array ( [1] => -2147483646 ) + +Warning: non-representable float 4294967296 was cast to int in %s on line %d Array ( [1] => 0 @@ -227,10 +239,14 @@ Array ( [1] => 0 ) + +Warning: non-representable float 2147483650 was cast to int in %s on line %d Array ( [1] => -2147483646 ) + +Warning: non-representable float 4294967296 was cast to int in %s on line %d Array ( [1] => 0 @@ -299,10 +315,14 @@ Array ( [1] => 0 ) + +Warning: non-representable float 2147483650 was cast to int in %s on line %d Array ( [1] => -2147483646 ) + +Warning: non-representable float 4294967296 was cast to int in %s on line %d Array ( [1] => 0 diff --git a/ext/standard/tests/strings/pack64.phpt b/ext/standard/tests/strings/pack64.phpt index 84e69008284d4..0f492bc6e5efe 100644 --- a/ext/standard/tests/strings/pack64.phpt +++ b/ext/standard/tests/strings/pack64.phpt @@ -37,7 +37,7 @@ print_r(unpack("i", pack("i", -2147483647))); print_r(unpack("i", pack("i", -2147483648))); // Min int32 print_r(unpack("I", pack("I", 4294967295))); // Max uint32 ?> ---EXPECT-- +--EXPECTF-- Array ( [1] => 281474976710654 @@ -46,6 +46,8 @@ Array ( [1] => 0 ) + +Warning: non-representable float 9.223372036854776E+18 was cast to int in %s on line %d Array ( [1] => -9223372036854775808 @@ -54,6 +56,8 @@ Array ( [1] => -1 ) + +Warning: non-representable float 9.223372036854776E+18 was cast to int in %s on line %d Array ( [1] => -9223372036854775808 @@ -66,6 +70,8 @@ Array ( [1] => 0 ) + +Warning: non-representable float 9.223372036854776E+18 was cast to int in %s on line %d Array ( [1] => -9223372036854775808 @@ -74,6 +80,8 @@ Array ( [1] => -1 ) + +Warning: non-representable float 9.223372036854776E+18 was cast to int in %s on line %d Array ( [1] => -9223372036854775808 @@ -86,6 +94,8 @@ Array ( [1] => 0 ) + +Warning: non-representable float 9.223372036854776E+18 was cast to int in %s on line %d Array ( [1] => -9223372036854775808 @@ -94,6 +104,8 @@ Array ( [1] => -1 ) + +Warning: non-representable float 9.223372036854776E+18 was cast to int in %s on line %d Array ( [1] => -9223372036854775808 @@ -106,6 +118,8 @@ Array ( [1] => 0 ) + +Warning: non-representable float 9.223372036854776E+18 was cast to int in %s on line %d Array ( [1] => -9223372036854775808 @@ -114,6 +128,8 @@ Array ( [1] => -1 ) + +Warning: non-representable float 9.223372036854776E+18 was cast to int in %s on line %d Array ( [1] => -9223372036854775808 diff --git a/ext/standard/tests/strings/vprintf_variation12.phpt b/ext/standard/tests/strings/vprintf_variation12.phpt index cac53da18f4d8..157aacb41de21 100644 --- a/ext/standard/tests/strings/vprintf_variation12.phpt +++ b/ext/standard/tests/strings/vprintf_variation12.phpt @@ -74,10 +74,16 @@ foreach($args_array as $args) { } ?> ---EXPECT-- +--EXPECTF-- *** Testing vprintf() : octal formats and non-octal values *** -- Iteration 1 -- + +Warning: non-representable float 20000000000 was cast to int in %s on line %d + +Warning: non-representable float 2000000000000 was cast to int in %s on line %d + +Warning: non-representable float 22000000000000 was cast to int in %s on line %d 2 0 12 361100 37777775456 2322 diff --git a/ext/standard/tests/strings/vprintf_variation14.phpt b/ext/standard/tests/strings/vprintf_variation14.phpt index ce65e8726d871..c273224f6939d 100644 --- a/ext/standard/tests/strings/vprintf_variation14.phpt +++ b/ext/standard/tests/strings/vprintf_variation14.phpt @@ -75,10 +75,16 @@ foreach($args_array as $args) { } ?> ---EXPECT-- +--EXPECTF-- *** Testing vprintf() : hexa formats and non-hexa values *** -- Iteration 1 -- + +Warning: non-representable float 20000000000 was cast to int in %s on line %d + +Warning: non-representable float 2000000000000 was cast to int in %s on line %d + +Warning: non-representable float 22000000000000 was cast to int in %s on line %d 2 0 a 1e240 x fffffb2e 4d2 diff --git a/ext/standard/tests/strings/vprintf_variation15.phpt b/ext/standard/tests/strings/vprintf_variation15.phpt index c8ae74f2aa75e..c1898564ae97d 100644 --- a/ext/standard/tests/strings/vprintf_variation15.phpt +++ b/ext/standard/tests/strings/vprintf_variation15.phpt @@ -44,7 +44,7 @@ foreach($formats as $format) { } ?> ---EXPECT-- +--EXPECTF-- *** Testing vprintf() : unsigned formats and unsigned values *** -- Iteration 1 -- @@ -52,10 +52,14 @@ foreach($formats as $format) { int(16) -- Iteration 2 -- + +Warning: non-representable float 12345678900 was cast to int in %s on line %d 3755744308 1234 12345 int(21) -- Iteration 3 -- + +Warning: non-representable float 101234567000 was cast to int in %s on line %d 1234000 2450319192 120 int(25) diff --git a/ext/standard/tests/strings/vprintf_variation15_64bit.phpt b/ext/standard/tests/strings/vprintf_variation15_64bit.phpt index 2729e8f54af74..1494272784544 100644 --- a/ext/standard/tests/strings/vprintf_variation15_64bit.phpt +++ b/ext/standard/tests/strings/vprintf_variation15_64bit.phpt @@ -44,7 +44,7 @@ foreach($formats as $format) { } ?> ---EXPECT-- +--EXPECTF-- *** Testing vprintf() : unsigned formats and unsigned values *** -- Iteration 1 -- @@ -56,6 +56,8 @@ int(16) int(22) -- Iteration 3 -- + +Warning: non-representable float 1.0E+21 was cast to int in %s on line %d 1234000 3875820019684212736 120 int(34) diff --git a/ext/standard/tests/strings/vprintf_variation16.phpt b/ext/standard/tests/strings/vprintf_variation16.phpt index 70ecdab99e071..73ab1b5d326bd 100644 --- a/ext/standard/tests/strings/vprintf_variation16.phpt +++ b/ext/standard/tests/strings/vprintf_variation16.phpt @@ -66,10 +66,16 @@ foreach($args_array as $args) { $counter++; } ?> ---EXPECT-- +--EXPECTF-- *** Testing vprintf() : unsigned formats and signed & other types of values *** -- Iteration 1 -- + +Warning: non-representable float 20000000000 was cast to int in %s on line %d + +Warning: non-representable float 2000000000000 was cast to int in %s on line %d + +Warning: non-representable float 22000000000000 was cast to int in %s on line %d 2 0 10 123456 123456 1234 2820130816 2840207360 1177509888 diff --git a/ext/standard/tests/strings/vprintf_variation4.phpt b/ext/standard/tests/strings/vprintf_variation4.phpt index 63018a9db8a86..1badcfb83423b 100644 --- a/ext/standard/tests/strings/vprintf_variation4.phpt +++ b/ext/standard/tests/strings/vprintf_variation4.phpt @@ -67,10 +67,12 @@ foreach($args_array as $args) { } ?> ---EXPECT-- +--EXPECTF-- *** Testing vprintf() : int formats and non-integer values *** -- Iteration 1 -- + +Warning: non-representable float 20000000000 was cast to int in %s on line %d 2 +0 10 123456 -1234 1234 -1474836480 200000 4000 22000000 diff --git a/main/php_variables.c b/main/php_variables.c index e0fe979d94d9b..971e1c77ea9f4 100644 --- a/main/php_variables.c +++ b/main/php_variables.c @@ -745,7 +745,7 @@ static inline void php_register_server_variables(void) /* store request init time */ ZVAL_DOUBLE(&tmp, sapi_get_request_time()); php_register_variable_quick("REQUEST_TIME_FLOAT", sizeof("REQUEST_TIME_FLOAT")-1, &tmp, ht); - ZVAL_LONG(&tmp, zend_dval_to_lval(Z_DVAL(tmp))); + ZVAL_LONG(&tmp, zend_dval_to_lval_silent(Z_DVAL(tmp))); php_register_variable_quick("REQUEST_TIME", sizeof("REQUEST_TIME")-1, &tmp, ht); } /* }}} */ diff --git a/tests/lang/bug27354.phpt b/tests/lang/bug27354.phpt index 5d18910bc9f32..89efed29ac6f7 100644 --- a/tests/lang/bug27354.phpt +++ b/tests/lang/bug27354.phpt @@ -10,7 +10,7 @@ var_dump(-2147483648 % -2); --EXPECTF-- int(0) -Deprecated: Implicit conversion from float -9.223372036860776E+18 to int loses precision in %s on line %d +Warning: non-representable float -9.223372036860776E+18 was cast to int in %s on line %d int(0) int(0) int(0) diff --git a/tests/lang/operators/bitwiseNot_basiclong_64bit.phpt b/tests/lang/operators/bitwiseNot_basiclong_64bit.phpt index 0e701051f5f47..583b5c070aafb 100644 --- a/tests/lang/operators/bitwiseNot_basiclong_64bit.phpt +++ b/tests/lang/operators/bitwiseNot_basiclong_64bit.phpt @@ -52,7 +52,7 @@ int(-4294967294) int(-9223372036854775807) --- testing: 9.2233720368548E+18 --- -Deprecated: Implicit conversion from float 9.223372036854776E+18 to int loses precision in %s on line %d +Warning: non-representable float 9.223372036854776E+18 was cast to int in %s on line %d int(9223372036854775807) --- testing: -9223372036854775807 --- int(9223372036854775806) From f31e3ea792ba94c31d8ba4d8b3d2475fa89e6aa8 Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Sun, 21 Sep 2025 12:52:46 +0100 Subject: [PATCH 2/8] Handle UAFs --- .../non-rep-float-as-int-extra1.phpt | 19 +++ .../non-rep-float-as-int-extra2.phpt | 17 +++ .../non-rep-float-as-int-extra3.phpt | 18 +++ .../non-rep-float-as-int-extra4.phpt | 18 +++ Zend/zend_execute.c | 20 +++ Zend/zend_operators.c | 10 +- Zend/zend_vm_def.h | 10 ++ Zend/zend_vm_execute.h | 120 ++++++++++++++++++ 8 files changed, 230 insertions(+), 2 deletions(-) create mode 100644 Zend/tests/type_coercion/float_to_int/non-rep-float-as-int-extra1.phpt create mode 100644 Zend/tests/type_coercion/float_to_int/non-rep-float-as-int-extra2.phpt create mode 100644 Zend/tests/type_coercion/float_to_int/non-rep-float-as-int-extra3.phpt create mode 100644 Zend/tests/type_coercion/float_to_int/non-rep-float-as-int-extra4.phpt diff --git a/Zend/tests/type_coercion/float_to_int/non-rep-float-as-int-extra1.phpt b/Zend/tests/type_coercion/float_to_int/non-rep-float-as-int-extra1.phpt new file mode 100644 index 0000000000000..8acd4b9efd720 --- /dev/null +++ b/Zend/tests/type_coercion/float_to_int/non-rep-float-as-int-extra1.phpt @@ -0,0 +1,19 @@ +--TEST-- +Non rep float string to int conversions should not crash when modified +--FILE-- + +--EXPECTF-- +non-representable float-string 1.0E+4%d was cast to int +Implicit conversion from float-string "1.0E+4%d" to int loses precision +int(9223372036854775807) diff --git a/Zend/tests/type_coercion/float_to_int/non-rep-float-as-int-extra2.phpt b/Zend/tests/type_coercion/float_to_int/non-rep-float-as-int-extra2.phpt new file mode 100644 index 0000000000000..8cc4f39e6fb48 --- /dev/null +++ b/Zend/tests/type_coercion/float_to_int/non-rep-float-as-int-extra2.phpt @@ -0,0 +1,17 @@ +--TEST-- +Non rep float string to int conversions should not crash when modified +--FILE-- + +--EXPECT-- +non-representable float 1.0E+42 was cast to int diff --git a/Zend/tests/type_coercion/float_to_int/non-rep-float-as-int-extra3.phpt b/Zend/tests/type_coercion/float_to_int/non-rep-float-as-int-extra3.phpt new file mode 100644 index 0000000000000..463adb579a684 --- /dev/null +++ b/Zend/tests/type_coercion/float_to_int/non-rep-float-as-int-extra3.phpt @@ -0,0 +1,18 @@ +--TEST-- +Non rep float string to int conversions should not crash when modified +--FILE-- + +--EXPECT-- +non-representable float 1.0E+42 was cast to int +bool(false) diff --git a/Zend/tests/type_coercion/float_to_int/non-rep-float-as-int-extra4.phpt b/Zend/tests/type_coercion/float_to_int/non-rep-float-as-int-extra4.phpt new file mode 100644 index 0000000000000..34c5414204523 --- /dev/null +++ b/Zend/tests/type_coercion/float_to_int/non-rep-float-as-int-extra4.phpt @@ -0,0 +1,18 @@ +--TEST-- +Non rep float string to int conversions should not crash when modified +--FILE-- + +--EXPECT-- +non-representable float 1.0E+42 was cast to int +bool(false) diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index 353a75d816bbf..5665cc0c3f784 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -3241,7 +3241,17 @@ static zend_never_inline zval* ZEND_FASTCALL zend_find_array_dim_slow(HashTable zend_ulong hval; if (Z_TYPE_P(offset) == IS_DOUBLE) { + /* The array may be destroyed while throwing a warning in case the float is not representable as an int. + * Temporarily increase the refcount to detect this situation. */ + GC_TRY_ADDREF(ht); hval = zend_dval_to_lval_safe(Z_DVAL_P(offset)); + if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) { + zend_array_destroy(ht); + return NULL; + } + if (EG(exception)) { + return NULL; + } num_idx: return zend_hash_index_find(ht, hval); } else if (Z_TYPE_P(offset) == IS_NULL) { @@ -3380,7 +3390,17 @@ static zend_never_inline bool ZEND_FASTCALL zend_array_key_exists_fast(HashTable key = Z_REFVAL_P(key); goto try_again; } else if (Z_TYPE_P(key) == IS_DOUBLE) { + /* The array may be destroyed while throwing a warning in case the float is not representable as an int. + * Temporarily increase the refcount to detect this situation. */ + GC_TRY_ADDREF(ht); hval = zend_dval_to_lval_safe(Z_DVAL_P(key)); + if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) { + zend_array_destroy(ht); + return false; + } + if (EG(exception)) { + return false; + } goto num_key; } else if (Z_TYPE_P(key) == IS_FALSE) { hval = 0; diff --git a/Zend/zend_operators.c b/Zend/zend_operators.c index 5ea5cb61593fe..e87b2105eadfa 100644 --- a/Zend/zend_operators.c +++ b/Zend/zend_operators.c @@ -415,6 +415,8 @@ static zend_never_inline zend_long ZEND_FASTCALL zendi_try_get_long(const zval * zend_error(E_WARNING, "A non-numeric value encountered"); if (UNEXPECTED(EG(exception))) { *failed = 1; + zend_tmp_string_release(op_str); + return 0; } } if (EXPECTED(type == IS_LONG)) { @@ -425,14 +427,18 @@ static zend_never_inline zend_long ZEND_FASTCALL zendi_try_get_long(const zval * * We use use saturating conversion to emulate strtol()'s * behaviour. */ + if (op_str == NULL) { + /* zend_dval_to_lval_cap() can emit a warning so always do the copy here */ + op_str = zend_string_copy(Z_STR_P(op)); + } lval = zend_dval_to_lval_cap(dval); if (!zend_is_long_compatible(dval, lval)) { - zend_incompatible_string_to_long_error(op_str ? op_str : Z_STR_P(op)); + zend_incompatible_string_to_long_error(op_str); if (UNEXPECTED(EG(exception))) { *failed = 1; } } - zend_tmp_string_release(op_str); + zend_string_release(op_str); return lval; } } diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index 3d6463d064873..3ebf816cf3817 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -6751,7 +6751,17 @@ ZEND_VM_C_LABEL(num_index_dim): offset = Z_REFVAL_P(offset); ZEND_VM_C_GOTO(offset_again); } else if (Z_TYPE_P(offset) == IS_DOUBLE) { + /* The array may be destroyed while throwing a warning in case the float is not representable as an int. + * Temporarily increase the refcount to detect this situation. */ + GC_TRY_ADDREF(ht); hval = zend_dval_to_lval_safe(Z_DVAL_P(offset)); + if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) { + zend_array_destroy(ht); + break; + } + if (EG(exception)) { + break; + } ZEND_VM_C_GOTO(num_index_dim); } else if (Z_TYPE_P(offset) == IS_NULL) { key = ZSTR_EMPTY_ALLOC(); diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index 33c8e9c223173..b0d6f2bc33d96 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -26627,7 +26627,17 @@ static ZEND_OPCODE_HANDLER_RET ZEND_OPCODE_HANDLER_FUNC_CCONV ZEND_UNSET_DIM_SPE offset = Z_REFVAL_P(offset); goto offset_again; } else if (Z_TYPE_P(offset) == IS_DOUBLE) { + /* The array may be destroyed while throwing a warning in case the float is not representable as an int. + * Temporarily increase the refcount to detect this situation. */ + GC_TRY_ADDREF(ht); hval = zend_dval_to_lval_safe(Z_DVAL_P(offset)); + if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) { + zend_array_destroy(ht); + break; + } + if (EG(exception)) { + break; + } goto num_index_dim; } else if (Z_TYPE_P(offset) == IS_NULL) { key = ZSTR_EMPTY_ALLOC(); @@ -29168,7 +29178,17 @@ static ZEND_OPCODE_HANDLER_RET ZEND_OPCODE_HANDLER_FUNC_CCONV ZEND_UNSET_DIM_SPE offset = Z_REFVAL_P(offset); goto offset_again; } else if (Z_TYPE_P(offset) == IS_DOUBLE) { + /* The array may be destroyed while throwing a warning in case the float is not representable as an int. + * Temporarily increase the refcount to detect this situation. */ + GC_TRY_ADDREF(ht); hval = zend_dval_to_lval_safe(Z_DVAL_P(offset)); + if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) { + zend_array_destroy(ht); + break; + } + if (EG(exception)) { + break; + } goto num_index_dim; } else if (Z_TYPE_P(offset) == IS_NULL) { key = ZSTR_EMPTY_ALLOC(); @@ -33687,7 +33707,17 @@ static ZEND_OPCODE_HANDLER_RET ZEND_OPCODE_HANDLER_FUNC_CCONV ZEND_UNSET_DIM_SPE offset = Z_REFVAL_P(offset); goto offset_again; } else if (Z_TYPE_P(offset) == IS_DOUBLE) { + /* The array may be destroyed while throwing a warning in case the float is not representable as an int. + * Temporarily increase the refcount to detect this situation. */ + GC_TRY_ADDREF(ht); hval = zend_dval_to_lval_safe(Z_DVAL_P(offset)); + if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) { + zend_array_destroy(ht); + break; + } + if (EG(exception)) { + break; + } goto num_index_dim; } else if (Z_TYPE_P(offset) == IS_NULL) { key = ZSTR_EMPTY_ALLOC(); @@ -46191,7 +46221,17 @@ static ZEND_OPCODE_HANDLER_RET ZEND_OPCODE_HANDLER_FUNC_CCONV ZEND_UNSET_DIM_SPE offset = Z_REFVAL_P(offset); goto offset_again; } else if (Z_TYPE_P(offset) == IS_DOUBLE) { + /* The array may be destroyed while throwing a warning in case the float is not representable as an int. + * Temporarily increase the refcount to detect this situation. */ + GC_TRY_ADDREF(ht); hval = zend_dval_to_lval_safe(Z_DVAL_P(offset)); + if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) { + zend_array_destroy(ht); + break; + } + if (EG(exception)) { + break; + } goto num_index_dim; } else if (Z_TYPE_P(offset) == IS_NULL) { key = ZSTR_EMPTY_ALLOC(); @@ -50020,7 +50060,17 @@ static ZEND_OPCODE_HANDLER_RET ZEND_OPCODE_HANDLER_FUNC_CCONV ZEND_UNSET_DIM_SPE offset = Z_REFVAL_P(offset); goto offset_again; } else if (Z_TYPE_P(offset) == IS_DOUBLE) { + /* The array may be destroyed while throwing a warning in case the float is not representable as an int. + * Temporarily increase the refcount to detect this situation. */ + GC_TRY_ADDREF(ht); hval = zend_dval_to_lval_safe(Z_DVAL_P(offset)); + if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) { + zend_array_destroy(ht); + break; + } + if (EG(exception)) { + break; + } goto num_index_dim; } else if (Z_TYPE_P(offset) == IS_NULL) { key = ZSTR_EMPTY_ALLOC(); @@ -55769,7 +55819,17 @@ static ZEND_OPCODE_HANDLER_RET ZEND_OPCODE_HANDLER_FUNC_CCONV ZEND_UNSET_DIM_SPE offset = Z_REFVAL_P(offset); goto offset_again; } else if (Z_TYPE_P(offset) == IS_DOUBLE) { + /* The array may be destroyed while throwing a warning in case the float is not representable as an int. + * Temporarily increase the refcount to detect this situation. */ + GC_TRY_ADDREF(ht); hval = zend_dval_to_lval_safe(Z_DVAL_P(offset)); + if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) { + zend_array_destroy(ht); + break; + } + if (EG(exception)) { + break; + } goto num_index_dim; } else if (Z_TYPE_P(offset) == IS_NULL) { key = ZSTR_EMPTY_ALLOC(); @@ -81788,7 +81848,17 @@ static ZEND_OPCODE_HANDLER_RET ZEND_OPCODE_HANDLER_CCONV ZEND_UNSET_DIM_SPEC_VAR offset = Z_REFVAL_P(offset); goto offset_again; } else if (Z_TYPE_P(offset) == IS_DOUBLE) { + /* The array may be destroyed while throwing a warning in case the float is not representable as an int. + * Temporarily increase the refcount to detect this situation. */ + GC_TRY_ADDREF(ht); hval = zend_dval_to_lval_safe(Z_DVAL_P(offset)); + if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) { + zend_array_destroy(ht); + break; + } + if (EG(exception)) { + break; + } goto num_index_dim; } else if (Z_TYPE_P(offset) == IS_NULL) { key = ZSTR_EMPTY_ALLOC(); @@ -84329,7 +84399,17 @@ static ZEND_OPCODE_HANDLER_RET ZEND_OPCODE_HANDLER_CCONV ZEND_UNSET_DIM_SPEC_VAR offset = Z_REFVAL_P(offset); goto offset_again; } else if (Z_TYPE_P(offset) == IS_DOUBLE) { + /* The array may be destroyed while throwing a warning in case the float is not representable as an int. + * Temporarily increase the refcount to detect this situation. */ + GC_TRY_ADDREF(ht); hval = zend_dval_to_lval_safe(Z_DVAL_P(offset)); + if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) { + zend_array_destroy(ht); + break; + } + if (EG(exception)) { + break; + } goto num_index_dim; } else if (Z_TYPE_P(offset) == IS_NULL) { key = ZSTR_EMPTY_ALLOC(); @@ -88848,7 +88928,17 @@ static ZEND_OPCODE_HANDLER_RET ZEND_OPCODE_HANDLER_CCONV ZEND_UNSET_DIM_SPEC_VAR offset = Z_REFVAL_P(offset); goto offset_again; } else if (Z_TYPE_P(offset) == IS_DOUBLE) { + /* The array may be destroyed while throwing a warning in case the float is not representable as an int. + * Temporarily increase the refcount to detect this situation. */ + GC_TRY_ADDREF(ht); hval = zend_dval_to_lval_safe(Z_DVAL_P(offset)); + if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) { + zend_array_destroy(ht); + break; + } + if (EG(exception)) { + break; + } goto num_index_dim; } else if (Z_TYPE_P(offset) == IS_NULL) { key = ZSTR_EMPTY_ALLOC(); @@ -101352,7 +101442,17 @@ static ZEND_OPCODE_HANDLER_RET ZEND_OPCODE_HANDLER_CCONV ZEND_UNSET_DIM_SPEC_CV_ offset = Z_REFVAL_P(offset); goto offset_again; } else if (Z_TYPE_P(offset) == IS_DOUBLE) { + /* The array may be destroyed while throwing a warning in case the float is not representable as an int. + * Temporarily increase the refcount to detect this situation. */ + GC_TRY_ADDREF(ht); hval = zend_dval_to_lval_safe(Z_DVAL_P(offset)); + if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) { + zend_array_destroy(ht); + break; + } + if (EG(exception)) { + break; + } goto num_index_dim; } else if (Z_TYPE_P(offset) == IS_NULL) { key = ZSTR_EMPTY_ALLOC(); @@ -105181,7 +105281,17 @@ static ZEND_OPCODE_HANDLER_RET ZEND_OPCODE_HANDLER_CCONV ZEND_UNSET_DIM_SPEC_CV_ offset = Z_REFVAL_P(offset); goto offset_again; } else if (Z_TYPE_P(offset) == IS_DOUBLE) { + /* The array may be destroyed while throwing a warning in case the float is not representable as an int. + * Temporarily increase the refcount to detect this situation. */ + GC_TRY_ADDREF(ht); hval = zend_dval_to_lval_safe(Z_DVAL_P(offset)); + if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) { + zend_array_destroy(ht); + break; + } + if (EG(exception)) { + break; + } goto num_index_dim; } else if (Z_TYPE_P(offset) == IS_NULL) { key = ZSTR_EMPTY_ALLOC(); @@ -110828,7 +110938,17 @@ static ZEND_OPCODE_HANDLER_RET ZEND_OPCODE_HANDLER_CCONV ZEND_UNSET_DIM_SPEC_CV_ offset = Z_REFVAL_P(offset); goto offset_again; } else if (Z_TYPE_P(offset) == IS_DOUBLE) { + /* The array may be destroyed while throwing a warning in case the float is not representable as an int. + * Temporarily increase the refcount to detect this situation. */ + GC_TRY_ADDREF(ht); hval = zend_dval_to_lval_safe(Z_DVAL_P(offset)); + if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) { + zend_array_destroy(ht); + break; + } + if (EG(exception)) { + break; + } goto num_index_dim; } else if (Z_TYPE_P(offset) == IS_NULL) { key = ZSTR_EMPTY_ALLOC(); From 5c9f813d738e5a1980b6b9e50909c23f59323f86 Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Sun, 21 Sep 2025 13:38:44 +0100 Subject: [PATCH 3/8] Fix JIT str offset handling --- ext/opcache/jit/zend_jit_helpers.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/ext/opcache/jit/zend_jit_helpers.c b/ext/opcache/jit/zend_jit_helpers.c index 04fbe15a26d5b..d49d5ee3007e4 100644 --- a/ext/opcache/jit/zend_jit_helpers.c +++ b/ext/opcache/jit/zend_jit_helpers.c @@ -1274,14 +1274,17 @@ static void ZEND_FASTCALL zend_jit_fetch_dim_str_is_helper(zend_string *str, zva switch (Z_TYPE_P(dim)) { /* case IS_LONG: */ case IS_STRING: - if (IS_LONG == is_numeric_string(Z_STRVAL_P(dim), Z_STRLEN_P(dim), NULL, NULL, false)) { - break; + if (IS_LONG == is_numeric_string(Z_STRVAL_P(dim), Z_STRLEN_P(dim), &offset, NULL, false)) { + goto out; } ZVAL_NULL(result); return; + case IS_DOUBLE: + offset = zend_dval_to_lval_silent(Z_DVAL_P(dim)); + goto out; case IS_UNDEF: zend_jit_undefined_op_helper(EG(current_execute_data)->opline->op2.var); - case IS_DOUBLE: + ZEND_FALLTHROUGH; case IS_NULL: case IS_FALSE: case IS_TRUE: @@ -1302,6 +1305,7 @@ static void ZEND_FASTCALL zend_jit_fetch_dim_str_is_helper(zend_string *str, zva offset = Z_LVAL_P(dim); } +out: if ((zend_ulong)offset >= (zend_ulong)ZSTR_LEN(str)) { if (offset < 0) { /* Handle negative offset */ From 7e3520c9b83e6670977cac26a6ddaf01f8d5fdb3 Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Sun, 21 Sep 2025 13:39:57 +0100 Subject: [PATCH 4/8] Fix new test for 32 bit --- .../type_coercion/float_to_int/non-rep-float-as-int-extra1.phpt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Zend/tests/type_coercion/float_to_int/non-rep-float-as-int-extra1.phpt b/Zend/tests/type_coercion/float_to_int/non-rep-float-as-int-extra1.phpt index 8acd4b9efd720..c32cc3f601796 100644 --- a/Zend/tests/type_coercion/float_to_int/non-rep-float-as-int-extra1.phpt +++ b/Zend/tests/type_coercion/float_to_int/non-rep-float-as-int-extra1.phpt @@ -16,4 +16,4 @@ var_dump($b | 1); --EXPECTF-- non-representable float-string 1.0E+4%d was cast to int Implicit conversion from float-string "1.0E+4%d" to int loses precision -int(9223372036854775807) +int(%d) From d5c51576ee2b3edca5a887f29ac7fce4a272c24b Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Sun, 21 Sep 2025 14:01:37 +0100 Subject: [PATCH 5/8] Add i to F print f modifier for 32 bit floats written as ints? --- Zend/tests/offsets/test_offset_helpers.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Zend/tests/offsets/test_offset_helpers.inc b/Zend/tests/offsets/test_offset_helpers.inc index 8d4ccadef56ac..a09290360e011 100644 --- a/Zend/tests/offsets/test_offset_helpers.inc +++ b/Zend/tests/offsets/test_offset_helpers.inc @@ -85,7 +85,7 @@ function expectf_to_regex(string $wanted): string '%d' => '\d+', '%x' => '[0-9a-fA-F]+', '%f' => '[+-]?(?:\d+|(?=\.\d))(?:\.\d+)?(?:[Ee][+-]?\d+)?', - '%F' => '([+-]?(?:\d+|(?=\.\d))(?:\.\d+)?(?:[Ee][+-]?\d+)?)|(NAN)|(INF)', + '%F' => '([+-]?(?:\d+|(?=\.\d))(?:\.\d+)?(?:[Ee][+-]?\d+)?)|(NAN)|(INF)|([+-]?\d+)', '%c' => '.', '%0' => '\x00', ]); From 7f6e025fb9d34d7e6ac200a6c6102001e3f83128 Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Sun, 21 Sep 2025 22:31:10 +0100 Subject: [PATCH 6/8] Update wording --- .../bitwise_not_precision_exception.phpt | 2 +- Zend/tests/bug46701.phpt | 10 ++-- Zend/tests/falsetoarray_003.phpt | 2 +- Zend/tests/int_overflow_32bit.phpt | 10 ++-- Zend/tests/int_overflow_64bit.phpt | 6 +-- Zend/tests/int_underflow_32bit.phpt | 8 ++-- ...rrayObject_container_offset_behaviour.phpt | 46 +++++++++---------- .../array_container_offset_behaviour.phpt | 46 +++++++++---------- Zend/tests/offsets/array_offset_002.phpt | 2 +- .../false_container_offset_behaviour.phpt | 44 +++++++++--------- .../null_container_offset_behaviour.phpt | 44 +++++++++--------- .../string_container_offset_behaviour.phpt | 8 ++-- .../float_to_int/dval_to_lval_32.phpt | 12 ++--- .../float_to_int/dval_to_lval_64.phpt | 10 ++-- .../explicit_casts_should_not_warn.phpt | 10 ++-- .../explicit_casts_should_not_warn_32bit.phpt | 10 ++-- .../non-rep-float-as-int-extra1.phpt | 2 +- .../non-rep-float-as-int-extra2.phpt | 2 +- .../non-rep-float-as-int-extra3.phpt | 2 +- .../non-rep-float-as-int-extra4.phpt | 2 +- ...g_float_does_not_fit_zend_long_arrays.phpt | 12 ++--- ..._float_does_not_fit_zend_long_strings.phpt | 4 +- ..._does_not_fit_zend_long_strings_32bit.phpt | 4 +- .../type_coercion/int_special_values.phpt | 6 +-- Zend/zend_operators.c | 4 +- ext/date/tests/bug79015.phpt | 2 +- ext/intl/tests/gh13766.phpt | 2 +- ext/opcache/tests/jit/add_011.phpt | 2 +- ext/opcache/tests/jit/array_elem_002.phpt | 2 +- ext/opcache/tests/jit/gh19669-001.phpt | 2 +- ext/opcache/tests/jit/gh19669-002.phpt | 2 +- .../tests/jit/reg_alloc_003_32bits.phpt | 2 +- .../gettype_settype_variation2.phpt | 24 +++++----- .../tests/general_functions/intval.phpt | 8 ++-- ext/standard/tests/math/bug30695.phpt | 16 +++---- ext/standard/tests/strings/bug47842.phpt | 2 +- ext/standard/tests/strings/pack.phpt | 20 ++++---- ext/standard/tests/strings/pack64.phpt | 16 +++---- .../tests/strings/vprintf_variation12.phpt | 6 +-- .../tests/strings/vprintf_variation14.phpt | 6 +-- .../tests/strings/vprintf_variation15.phpt | 4 +- .../strings/vprintf_variation15_64bit.phpt | 2 +- .../tests/strings/vprintf_variation16.phpt | 6 +-- .../tests/strings/vprintf_variation4.phpt | 2 +- tests/lang/bug27354.phpt | 2 +- .../operators/bitwiseNot_basiclong_64bit.phpt | 2 +- 46 files changed, 219 insertions(+), 219 deletions(-) diff --git a/Zend/tests/bitwise_not_precision_exception.phpt b/Zend/tests/bitwise_not_precision_exception.phpt index 30d2978db5d2d..e28bf8f4e17b6 100644 --- a/Zend/tests/bitwise_not_precision_exception.phpt +++ b/Zend/tests/bitwise_not_precision_exception.phpt @@ -12,4 +12,4 @@ try { } ?> --EXPECT-- -non-representable float INF was cast to int +The float INF is not representable as an int, cast occurred diff --git a/Zend/tests/bug46701.phpt b/Zend/tests/bug46701.phpt index 5196bf2c6c42a..620d5209443e5 100644 --- a/Zend/tests/bug46701.phpt +++ b/Zend/tests/bug46701.phpt @@ -27,11 +27,11 @@ new foo; ?> --EXPECTF-- -Warning: non-representable float 3428599296 was cast to int in %s on line %d +Warning: The float 3428599296 is not representable as an int, cast occurred in %s on line %d -Warning: non-representable float 3459455488 was cast to int in %s on line %d +Warning: The float 3459455488 is not representable as an int, cast occurred in %s on line %d -Warning: non-representable float 3459616768 was cast to int in %s on line %d +Warning: The float 3459616768 is not representable as an int, cast occurred in %s on line %d array(3) { [-866368000]=> int(1) @@ -41,10 +41,10 @@ array(3) { int(3) } -Warning: non-representable float 3459455488 was cast to int in %s on line %d +Warning: The float 3459455488 is not representable as an int, cast occurred in %s on line %d int(2) -Warning: non-representable float 3459616768 was cast to int in %s on line %d +Warning: The float 3459616768 is not representable as an int, cast occurred in %s on line %d array(1) { [-835350528]=> int(3) diff --git a/Zend/tests/falsetoarray_003.phpt b/Zend/tests/falsetoarray_003.phpt index 9b816c3c8efdc..117e443ef9584 100644 --- a/Zend/tests/falsetoarray_003.phpt +++ b/Zend/tests/falsetoarray_003.phpt @@ -11,6 +11,6 @@ $a=[]; ?> DONE --EXPECTF-- -Err: non-representable float %f was cast to int +Err: The float %f is not representable as an int, cast occurred Err: Undefined array key %i DONE diff --git a/Zend/tests/int_overflow_32bit.phpt b/Zend/tests/int_overflow_32bit.phpt index 49f8f7a26397c..e337932bcd554 100644 --- a/Zend/tests/int_overflow_32bit.phpt +++ b/Zend/tests/int_overflow_32bit.phpt @@ -21,18 +21,18 @@ foreach ($doubles as $d) { echo "Done\n"; ?> --EXPECTF-- -Warning: non-representable float 2147483648 was cast to int in %s on line %d +Warning: The float 2147483648 is not representable as an int, cast occurred in %s on line %d int(-2147483648) -Warning: non-representable float 2147483649 was cast to int in %s on line %d +Warning: The float 2147483649 is not representable as an int, cast occurred in %s on line %d int(-2147483647) -Warning: non-representable float 2147483658 was cast to int in %s on line %d +Warning: The float 2147483658 is not representable as an int, cast occurred in %s on line %d int(-2147483638) -Warning: non-representable float 2147483748 was cast to int in %s on line %d +Warning: The float 2147483748 is not representable as an int, cast occurred in %s on line %d int(-2147483548) -Warning: non-representable float 2147484648 was cast to int in %s on line %d +Warning: The float 2147484648 is not representable as an int, cast occurred in %s on line %d int(-2147482648) Done diff --git a/Zend/tests/int_overflow_64bit.phpt b/Zend/tests/int_overflow_64bit.phpt index c4254d3c2a44c..cc14e14949ca8 100644 --- a/Zend/tests/int_overflow_64bit.phpt +++ b/Zend/tests/int_overflow_64bit.phpt @@ -25,13 +25,13 @@ echo "Done\n"; --EXPECTF-- int(9223372036854775807) -Warning: non-representable float %f was cast to int in %s on line %d +Warning: The float %f is not representable as an int, cast occurred in %s on line %d int(-9223372036854775808) -Warning: non-representable float %f was cast to int in %s on line %d +Warning: The float %f is not representable as an int, cast occurred in %s on line %d int(-9223372036854775808) -Warning: non-representable float %f was cast to int in %s on line %d +Warning: The float %f is not representable as an int, cast occurred in %s on line %d int(0) int(-9223372036854775808) int(-9223372036854775808) diff --git a/Zend/tests/int_underflow_32bit.phpt b/Zend/tests/int_underflow_32bit.phpt index d4b87ee3e5de9..88c0e79834b4b 100644 --- a/Zend/tests/int_underflow_32bit.phpt +++ b/Zend/tests/int_underflow_32bit.phpt @@ -23,15 +23,15 @@ echo "Done\n"; --EXPECTF-- int(-2147483648) -Warning: non-representable float -2147483649 was cast to int in %s on line %d +Warning: The float -2147483649 is not representable as an int, cast occurred in %s on line %d int(2147483647) -Warning: non-representable float -2147483658 was cast to int in %s on line %d +Warning: The float -2147483658 is not representable as an int, cast occurred in %s on line %d int(2147483638) -Warning: non-representable float -2147483748 was cast to int in %s on line %d +Warning: The float -2147483748 is not representable as an int, cast occurred in %s on line %d int(2147483548) -Warning: non-representable float -2147484648 was cast to int in %s on line %d +Warning: The float -2147484648 is not representable as an int, cast occurred in %s on line %d int(2147482648) Done diff --git a/Zend/tests/offsets/ArrayObject_container_offset_behaviour.phpt b/Zend/tests/offsets/ArrayObject_container_offset_behaviour.phpt index 107dab96be030..bcfbd4b317367 100644 --- a/Zend/tests/offsets/ArrayObject_container_offset_behaviour.phpt +++ b/Zend/tests/offsets/ArrayObject_container_offset_behaviour.phpt @@ -135,47 +135,47 @@ $EXPECTED_OUTPUT_FLOAT_OFFSETS_REGEX = '/^' . expectf_to_regex(EXPECTF_OUTPUT_FL const EXPECTF_OUTPUT_FLOAT_OOB_OFFSETS = << --EXPECT-- -Err: non-representable float 1.0E+20 was cast to int +Err: The float 1.0E+20 is not representable as an int, cast occurred array(0) { } diff --git a/Zend/tests/offsets/false_container_offset_behaviour.phpt b/Zend/tests/offsets/false_container_offset_behaviour.phpt index d10f6e424cd09..0647400baee0a 100644 --- a/Zend/tests/offsets/false_container_offset_behaviour.phpt +++ b/Zend/tests/offsets/false_container_offset_behaviour.phpt @@ -144,41 +144,41 @@ Write: Deprecated: Automatic conversion of false to array is deprecated in %s on line %d -Warning: non-representable float %F was cast to int in %s on line %d +Warning: The float %F is not representable as an int, cast occurred in %s on line %d Read: -Warning: non-representable float %F was cast to int in %s on line %d +Warning: The float %F is not representable as an int, cast occurred in %s on line %d int(5) Read-Write: -Warning: non-representable float %F was cast to int in %s on line %d +Warning: The float %F is not representable as an int, cast occurred in %s on line %d isset(): -Warning: non-representable float %F was cast to int in %s on line %d +Warning: The float %F is not representable as an int, cast occurred in %s on line %d bool(true) empty(): -Warning: non-representable float %F was cast to int in %s on line %d +Warning: The float %F is not representable as an int, cast occurred in %s on line %d bool(false) null coalesce: -Warning: non-representable float %F was cast to int in %s on line %d +Warning: The float %F is not representable as an int, cast occurred in %s on line %d int(25) Reference to dimension: -Warning: non-representable float %F was cast to int in %s on line %d +Warning: The float %F is not representable as an int, cast occurred in %s on line %d Value of reference: int(25) Value of container dimension after write to reference (should be int(100) if successful): -Warning: non-representable float %F was cast to int in %s on line %d +Warning: The float %F is not representable as an int, cast occurred in %s on line %d int(100) unset(): -Warning: non-representable float %F was cast to int in %s on line %d +Warning: The float %F is not representable as an int, cast occurred in %s on line %d Nested read: -Warning: non-representable float %F was cast to int in %s on line %d +Warning: The float %F is not representable as an int, cast occurred in %s on line %d Warning: Undefined array key 0 in %s on line %d @@ -186,37 +186,37 @@ Warning: Trying to access array offset on null in %s on line %d NULL Nested write: -Warning: non-representable float %F was cast to int in %s on line %d +Warning: The float %F is not representable as an int, cast occurred in %s on line %d -Warning: non-representable float %F was cast to int in %s on line %d +Warning: The float %F is not representable as an int, cast occurred in %s on line %d Nested Read-Write: -Warning: non-representable float %F was cast to int in %s on line %d +Warning: The float %F is not representable as an int, cast occurred in %s on line %d -Warning: non-representable float %F was cast to int in %s on line %d +Warning: The float %F is not representable as an int, cast occurred in %s on line %d Nested isset(): -Warning: non-representable float %F was cast to int in %s on line %d +Warning: The float %F is not representable as an int, cast occurred in %s on line %d -Warning: non-representable float %F was cast to int in %s on line %d +Warning: The float %F is not representable as an int, cast occurred in %s on line %d bool(true) Nested empty(): -Warning: non-representable float %F was cast to int in %s on line %d +Warning: The float %F is not representable as an int, cast occurred in %s on line %d -Warning: non-representable float %F was cast to int in %s on line %d +Warning: The float %F is not representable as an int, cast occurred in %s on line %d bool(false) Nested null coalesce: -Warning: non-representable float %F was cast to int in %s on line %d +Warning: The float %F is not representable as an int, cast occurred in %s on line %d -Warning: non-representable float %F was cast to int in %s on line %d +Warning: The float %F is not representable as an int, cast occurred in %s on line %d int(30) Nested unset(): -Warning: non-representable float %F was cast to int in %s on line %d +Warning: The float %F is not representable as an int, cast occurred in %s on line %d -Warning: non-representable float %F was cast to int in %s on line %d +Warning: The float %F is not representable as an int, cast occurred in %s on line %d OUTPUT; diff --git a/Zend/tests/offsets/null_container_offset_behaviour.phpt b/Zend/tests/offsets/null_container_offset_behaviour.phpt index b20eb92c3fb1f..2ac51937a0fe7 100644 --- a/Zend/tests/offsets/null_container_offset_behaviour.phpt +++ b/Zend/tests/offsets/null_container_offset_behaviour.phpt @@ -138,41 +138,41 @@ Warning: Trying to access array offset on null in %s on line %d NULL Write: -Warning: non-representable float %F was cast to int in %s on line %d +Warning: The float %F is not representable as an int, cast occurred in %s on line %d Read: -Warning: non-representable float %F was cast to int in %s on line %d +Warning: The float %F is not representable as an int, cast occurred in %s on line %d int(5) Read-Write: -Warning: non-representable float %F was cast to int in %s on line %d +Warning: The float %F is not representable as an int, cast occurred in %s on line %d isset(): -Warning: non-representable float %F was cast to int in %s on line %d +Warning: The float %F is not representable as an int, cast occurred in %s on line %d bool(true) empty(): -Warning: non-representable float %F was cast to int in %s on line %d +Warning: The float %F is not representable as an int, cast occurred in %s on line %d bool(false) null coalesce: -Warning: non-representable float %F was cast to int in %s on line %d +Warning: The float %F is not representable as an int, cast occurred in %s on line %d int(25) Reference to dimension: -Warning: non-representable float %F was cast to int in %s on line %d +Warning: The float %F is not representable as an int, cast occurred in %s on line %d Value of reference: int(25) Value of container dimension after write to reference (should be int(100) if successful): -Warning: non-representable float %F was cast to int in %s on line %d +Warning: The float %F is not representable as an int, cast occurred in %s on line %d int(100) unset(): -Warning: non-representable float %F was cast to int in %s on line %d +Warning: The float %F is not representable as an int, cast occurred in %s on line %d Nested read: -Warning: non-representable float %F was cast to int in %s on line %d +Warning: The float %F is not representable as an int, cast occurred in %s on line %d Warning: Undefined array key 0 in %s on line %d @@ -180,37 +180,37 @@ Warning: Trying to access array offset on null in %s on line %d NULL Nested write: -Warning: non-representable float %F was cast to int in %s on line %d +Warning: The float %F is not representable as an int, cast occurred in %s on line %d -Warning: non-representable float %F was cast to int in %s on line %d +Warning: The float %F is not representable as an int, cast occurred in %s on line %d Nested Read-Write: -Warning: non-representable float %F was cast to int in %s on line %d +Warning: The float %F is not representable as an int, cast occurred in %s on line %d -Warning: non-representable float %F was cast to int in %s on line %d +Warning: The float %F is not representable as an int, cast occurred in %s on line %d Nested isset(): -Warning: non-representable float %F was cast to int in %s on line %d +Warning: The float %F is not representable as an int, cast occurred in %s on line %d -Warning: non-representable float %F was cast to int in %s on line %d +Warning: The float %F is not representable as an int, cast occurred in %s on line %d bool(true) Nested empty(): -Warning: non-representable float %F was cast to int in %s on line %d +Warning: The float %F is not representable as an int, cast occurred in %s on line %d -Warning: non-representable float %F was cast to int in %s on line %d +Warning: The float %F is not representable as an int, cast occurred in %s on line %d bool(false) Nested null coalesce: -Warning: non-representable float %F was cast to int in %s on line %d +Warning: The float %F is not representable as an int, cast occurred in %s on line %d -Warning: non-representable float %F was cast to int in %s on line %d +Warning: The float %F is not representable as an int, cast occurred in %s on line %d int(30) Nested unset(): -Warning: non-representable float %F was cast to int in %s on line %d +Warning: The float %F is not representable as an int, cast occurred in %s on line %d -Warning: non-representable float %F was cast to int in %s on line %d +Warning: The float %F is not representable as an int, cast occurred in %s on line %d OUTPUT; diff --git a/Zend/tests/offsets/string_container_offset_behaviour.phpt b/Zend/tests/offsets/string_container_offset_behaviour.phpt index 1335aa1c08a55..9c752ebddd819 100644 --- a/Zend/tests/offsets/string_container_offset_behaviour.phpt +++ b/Zend/tests/offsets/string_container_offset_behaviour.phpt @@ -440,13 +440,13 @@ Warning: String offset cast occurred in %s on line %d Cannot use assign-op operators with string offsets isset(): -Warning: non-representable float %F was cast to int in %s on line %d +Warning: The float %F is not representable as an int, cast occurred in %s on line %d Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d bool(true) empty(): -Warning: non-representable float %F was cast to int in %s on line %d +Warning: The float %F is not representable as an int, cast occurred in %s on line %d Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d bool(false) @@ -474,13 +474,13 @@ Warning: String offset cast occurred in %s on line %d Cannot use string offset as an array Nested isset(): -Warning: non-representable float %F was cast to int in %s on line %d +Warning: The float %F is not representable as an int, cast occurred in %s on line %d Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d bool(true) Nested empty(): -Warning: non-representable float %F was cast to int in %s on line %d +Warning: The float %F is not representable as an int, cast occurred in %s on line %d Deprecated: Implicit conversion from float %F to int loses precision in %s on line %d bool(false) diff --git a/Zend/tests/type_coercion/float_to_int/dval_to_lval_32.phpt b/Zend/tests/type_coercion/float_to_int/dval_to_lval_32.phpt index 6dff6bcd43ef0..b4b4e70453eda 100644 --- a/Zend/tests/type_coercion/float_to_int/dval_to_lval_32.phpt +++ b/Zend/tests/type_coercion/float_to_int/dval_to_lval_32.phpt @@ -24,20 +24,20 @@ if (PHP_INT_SIZE != 4) ?> --EXPECTF-- -Warning: non-representable float -4.000000000000001E+21 was cast to int in %s on line %d +Warning: The float -4.000000000000001E+21 is not representable as an int, cast occurred in %s on line %d int(-2056257536) -Warning: non-representable float -4.0000000000000005E+21 was cast to int in %s on line %d +Warning: The float -4.0000000000000005E+21 is not representable as an int, cast occurred in %s on line %d int(-2055733248) -Warning: non-representable float -4.0E+21 was cast to int in %s on line %d +Warning: The float -4.0E+21 is not representable as an int, cast occurred in %s on line %d int(-2055208960) -Warning: non-representable float -3.9999999999999995E+21 was cast to int in %s on line %d +Warning: The float -3.9999999999999995E+21 is not representable as an int, cast occurred in %s on line %d int(-2054684672) -Warning: non-representable float -3.999999999999999E+21 was cast to int in %s on line %d +Warning: The float -3.999999999999999E+21 is not representable as an int, cast occurred in %s on line %d int(-2054160384) -Warning: non-representable float -2147483649.8 was cast to int in %s on line %d +Warning: The float -2147483649.8 is not representable as an int, cast occurred in %s on line %d int(2147483647) diff --git a/Zend/tests/type_coercion/float_to_int/dval_to_lval_64.phpt b/Zend/tests/type_coercion/float_to_int/dval_to_lval_64.phpt index d811d398114cc..993950534fc17 100644 --- a/Zend/tests/type_coercion/float_to_int/dval_to_lval_64.phpt +++ b/Zend/tests/type_coercion/float_to_int/dval_to_lval_64.phpt @@ -22,17 +22,17 @@ if (PHP_INT_SIZE != 8) ?> --EXPECTF-- -Warning: non-representable float -4.000000000000001E+21 was cast to int in %s on line %d +Warning: The float -4.000000000000001E+21 is not representable as an int, cast occurred in %s on line %d int(2943463994971652096) -Warning: non-representable float -4.0000000000000005E+21 was cast to int in %s on line %d +Warning: The float -4.0000000000000005E+21 is not representable as an int, cast occurred in %s on line %d int(2943463994972176384) -Warning: non-representable float -4.0E+21 was cast to int in %s on line %d +Warning: The float -4.0E+21 is not representable as an int, cast occurred in %s on line %d int(2943463994972700672) -Warning: non-representable float -3.9999999999999995E+21 was cast to int in %s on line %d +Warning: The float -3.9999999999999995E+21 is not representable as an int, cast occurred in %s on line %d int(2943463994973224960) -Warning: non-representable float -3.999999999999999E+21 was cast to int in %s on line %d +Warning: The float -3.999999999999999E+21 is not representable as an int, cast occurred in %s on line %d int(2943463994973749248) diff --git a/Zend/tests/type_coercion/float_to_int/explicit_casts_should_not_warn.phpt b/Zend/tests/type_coercion/float_to_int/explicit_casts_should_not_warn.phpt index f1273847321b0..5566b10b0a333 100644 --- a/Zend/tests/type_coercion/float_to_int/explicit_casts_should_not_warn.phpt +++ b/Zend/tests/type_coercion/float_to_int/explicit_casts_should_not_warn.phpt @@ -29,20 +29,20 @@ foreach($values as $value) { int(3) int(3) -Warning: non-representable float 1.0E+121 was cast to int in %s on line %d +Warning: The float 1.0E+121 is not representable as an int, cast occurred in %s on line %d int(0) -Warning: non-representable float 1.0E+301 was cast to int in %s on line %d +Warning: The float 1.0E+301 is not representable as an int, cast occurred in %s on line %d int(0) -Warning: non-representable float NAN was cast to int in %s on line %d +Warning: The float NAN is not representable as an int, cast occurred in %s on line %d int(0) int(3) int(3) -Warning: non-representable float-string 1.0E+121 was cast to int in %s on line %d +Warning: The float-string 1.0E+121 is not representable as an int, cast occurred in %s on line %d int(9223372036854775807) -Warning: non-representable float-string 1.0E+301 was cast to int in %s on line %d +Warning: The float-string 1.0E+301 is not representable as an int, cast occurred in %s on line %d int(9223372036854775807) int(0) diff --git a/Zend/tests/type_coercion/float_to_int/explicit_casts_should_not_warn_32bit.phpt b/Zend/tests/type_coercion/float_to_int/explicit_casts_should_not_warn_32bit.phpt index 3a2ea01f26821..3c90f0fd4d9c9 100644 --- a/Zend/tests/type_coercion/float_to_int/explicit_casts_should_not_warn_32bit.phpt +++ b/Zend/tests/type_coercion/float_to_int/explicit_casts_should_not_warn_32bit.phpt @@ -29,20 +29,20 @@ foreach($values as $value) { int(3) int(3) -Warning: non-representable float 1.0E+121 was cast to int in %s on line %d +Warning: The float 1.0E+121 is not representable as an int, cast occurred in %s on line %d int(0) -Warning: non-representable float 1.0E+301 was cast to int in %s on line %d +Warning: The float 1.0E+301 is not representable as an int, cast occurred in %s on line %d int(0) -Warning: non-representable float NAN was cast to int in %s on line %d +Warning: The float NAN is not representable as an int, cast occurred in %s on line %d int(0) int(3) int(3) -Warning: non-representable float-string 1.0E+121 was cast to int in %s on line %d +Warning: The float-string 1.0E+121 is not representable as an int, cast occurred in %s on line %d int(2147483647) -Warning: non-representable float-string 1.0E+301 was cast to int in %s on line %d +Warning: The float-string 1.0E+301 is not representable as an int, cast occurred in %s on line %d int(2147483647) int(0) diff --git a/Zend/tests/type_coercion/float_to_int/non-rep-float-as-int-extra1.phpt b/Zend/tests/type_coercion/float_to_int/non-rep-float-as-int-extra1.phpt index c32cc3f601796..1fb6f4efc45c0 100644 --- a/Zend/tests/type_coercion/float_to_int/non-rep-float-as-int-extra1.phpt +++ b/Zend/tests/type_coercion/float_to_int/non-rep-float-as-int-extra1.phpt @@ -14,6 +14,6 @@ var_dump($b | 1); ?> --EXPECTF-- -non-representable float-string 1.0E+4%d was cast to int +The float-string 1.0E+4%d is not representable as an int, cast occurred Implicit conversion from float-string "1.0E+4%d" to int loses precision int(%d) diff --git a/Zend/tests/type_coercion/float_to_int/non-rep-float-as-int-extra2.phpt b/Zend/tests/type_coercion/float_to_int/non-rep-float-as-int-extra2.phpt index 8cc4f39e6fb48..0e96acfd182d2 100644 --- a/Zend/tests/type_coercion/float_to_int/non-rep-float-as-int-extra2.phpt +++ b/Zend/tests/type_coercion/float_to_int/non-rep-float-as-int-extra2.phpt @@ -14,4 +14,4 @@ unset($ary[1.0E+42]); ?> --EXPECT-- -non-representable float 1.0E+42 was cast to int +The float 1.0E+42 is not representable as an int, cast occurred diff --git a/Zend/tests/type_coercion/float_to_int/non-rep-float-as-int-extra3.phpt b/Zend/tests/type_coercion/float_to_int/non-rep-float-as-int-extra3.phpt index 463adb579a684..0bfbeb01a2d00 100644 --- a/Zend/tests/type_coercion/float_to_int/non-rep-float-as-int-extra3.phpt +++ b/Zend/tests/type_coercion/float_to_int/non-rep-float-as-int-extra3.phpt @@ -14,5 +14,5 @@ var_dump(isset($ary[1.0E+42])); ?> --EXPECT-- -non-representable float 1.0E+42 was cast to int +The float 1.0E+42 is not representable as an int, cast occurred bool(false) diff --git a/Zend/tests/type_coercion/float_to_int/non-rep-float-as-int-extra4.phpt b/Zend/tests/type_coercion/float_to_int/non-rep-float-as-int-extra4.phpt index 34c5414204523..8134ce08d2eed 100644 --- a/Zend/tests/type_coercion/float_to_int/non-rep-float-as-int-extra4.phpt +++ b/Zend/tests/type_coercion/float_to_int/non-rep-float-as-int-extra4.phpt @@ -14,5 +14,5 @@ var_dump(\array_key_exists(1.0E+42, $ary)); ?> --EXPECT-- -non-representable float 1.0E+42 was cast to int +The float 1.0E+42 is not representable as an int, cast occurred bool(false) diff --git a/Zend/tests/type_coercion/float_to_int/warning_float_does_not_fit_zend_long_arrays.phpt b/Zend/tests/type_coercion/float_to_int/warning_float_does_not_fit_zend_long_arrays.phpt index ba8daa39f9f63..d707e2dc311c3 100644 --- a/Zend/tests/type_coercion/float_to_int/warning_float_does_not_fit_zend_long_arrays.phpt +++ b/Zend/tests/type_coercion/float_to_int/warning_float_does_not_fit_zend_long_arrays.phpt @@ -23,15 +23,15 @@ var_dump($array[$string_float]); ?> --EXPECTF-- -Warning: non-representable float 1.0E+121 was cast to int in %s on line %d +Warning: The float 1.0E+121 is not representable as an int, cast occurred in %s on line %d int(0) -Warning: non-representable float-string 1.0E+121 was cast to int in %s on line %d +Warning: The float-string 1.0E+121 is not representable as an int, cast occurred in %s on line %d bool(true) -Warning: non-representable float 1.0E+121 was cast to int in %s on line %d +Warning: The float 1.0E+121 is not representable as an int, cast occurred in %s on line %d -Warning: non-representable float 1.0E+121 was cast to int in %s on line %d +Warning: The float 1.0E+121 is not representable as an int, cast occurred in %s on line %d array(2) { [0]=> string(11) "Large float" @@ -45,13 +45,13 @@ array(2) { string(18) "String large float" } -Warning: non-representable float 1.0E+121 was cast to int in %s on line %d +Warning: The float 1.0E+121 is not representable as an int, cast occurred in %s on line %d string(1) "0" Warning: Undefined array key "1.0E+121" in %s on line %d NULL -Warning: non-representable float 1.0E+121 was cast to int in %s on line %d +Warning: The float 1.0E+121 is not representable as an int, cast occurred in %s on line %d string(1) "0" Warning: Undefined array key "1.0E+121" in %s on line %d diff --git a/Zend/tests/type_coercion/float_to_int/warning_float_does_not_fit_zend_long_strings.phpt b/Zend/tests/type_coercion/float_to_int/warning_float_does_not_fit_zend_long_strings.phpt index 1ba07baa1eaf4..5cba01392afed 100644 --- a/Zend/tests/type_coercion/float_to_int/warning_float_does_not_fit_zend_long_strings.phpt +++ b/Zend/tests/type_coercion/float_to_int/warning_float_does_not_fit_zend_long_strings.phpt @@ -75,10 +75,10 @@ var_dump($string); ?> --EXPECTF-- -Warning: non-representable float 1.0E+121 was cast to int in %s on line %d +Warning: The float 1.0E+121 is not representable as an int, cast occurred in %s on line %d int(0) -Warning: non-representable float-string 1.0E+121 was cast to int in %s on line %d +Warning: The float-string 1.0E+121 is not representable as an int, cast occurred in %s on line %d int(9223372036854775807) Attempt to read Float diff --git a/Zend/tests/type_coercion/float_to_int/warning_float_does_not_fit_zend_long_strings_32bit.phpt b/Zend/tests/type_coercion/float_to_int/warning_float_does_not_fit_zend_long_strings_32bit.phpt index ed711b25d557b..c610acfada01a 100644 --- a/Zend/tests/type_coercion/float_to_int/warning_float_does_not_fit_zend_long_strings_32bit.phpt +++ b/Zend/tests/type_coercion/float_to_int/warning_float_does_not_fit_zend_long_strings_32bit.phpt @@ -75,10 +75,10 @@ var_dump($string); ?> --EXPECTF-- -Warning: non-representable float 1.0E+121 was cast to int in %s on line %d +Warning: The float 1.0E+121 is not representable as an int, cast occurred in %s on line %d int(0) -Warning: non-representable float-string 1.0E+121 was cast to int in %s on line %d +Warning: The float-string 1.0E+121 is not representable as an int, cast occurred in %s on line %d int(2147483647) Attempt to read Float diff --git a/Zend/tests/type_coercion/int_special_values.phpt b/Zend/tests/type_coercion/int_special_values.phpt index 76000662b7b9d..e536ff988e0ae 100644 --- a/Zend/tests/type_coercion/int_special_values.phpt +++ b/Zend/tests/type_coercion/int_special_values.phpt @@ -23,12 +23,12 @@ int(0) float(INF) -Warning: non-representable float INF was cast to int in %s on line %d +Warning: The float INF is not representable as an int, cast occurred in %s on line %d int(0) float(-INF) -Warning: non-representable float -INF was cast to int in %s on line %d +Warning: The float -INF is not representable as an int, cast occurred in %s on line %d int(0) float(0) @@ -39,5 +39,5 @@ int(0) float(NAN) -Warning: non-representable float NAN was cast to int in %s on line %d +Warning: The float NAN is not representable as an int, cast occurred in %s on line %d int(0) diff --git a/Zend/zend_operators.c b/Zend/zend_operators.c index e87b2105eadfa..fdfce495aed0f 100644 --- a/Zend/zend_operators.c +++ b/Zend/zend_operators.c @@ -916,11 +916,11 @@ ZEND_API void ZEND_COLD zend_incompatible_string_to_long_error(const zend_string } ZEND_API void ZEND_COLD zend_oob_double_to_long_error(double d) { - zend_error_unchecked(E_WARNING, "non-representable float %.*H was cast to int", -1, d); + zend_error_unchecked(E_WARNING, "The float %.*H is not representable as an int, cast occurred", -1, d); } ZEND_API void ZEND_COLD zend_oob_string_to_long_error(double d) { - zend_error_unchecked(E_WARNING, "non-representable float-string %.*H was cast to int", -1, d); + zend_error_unchecked(E_WARNING, "The float-string %.*H is not representable as an int, cast occurred", -1, d); } ZEND_API zend_long ZEND_FASTCALL zval_get_long_func(const zval *op, bool is_strict) /* {{{ */ diff --git a/ext/date/tests/bug79015.phpt b/ext/date/tests/bug79015.phpt index a68014c6ca76b..b2f1a63fa4c21 100644 --- a/ext/date/tests/bug79015.phpt +++ b/ext/date/tests/bug79015.phpt @@ -6,7 +6,7 @@ $payload = 'O:12:"DateInterval":9:{s:1:"y";i:1;s:1:"m";i:0;s:1:"d";i:4;s:1:"h";i var_dump(unserialize($payload)); ?> --EXPECTF-- -Warning: non-representable float 9.99999999999E+18 was cast to int in %s on line %d +Warning: The float 9.99999999999E+18 is not representable as an int, cast occurred in %s on line %d object(DateInterval)#%d (%d) { ["y"]=> int(1) diff --git a/ext/intl/tests/gh13766.phpt b/ext/intl/tests/gh13766.phpt index 4d164b9465fe3..9ed8d985de470 100644 --- a/ext/intl/tests/gh13766.phpt +++ b/ext/intl/tests/gh13766.phpt @@ -32,4 +32,4 @@ int(%d) string(19) "America/Los_Angeles" IntlDateFormatter::parseToCalendar(): Argument #2 ($offset) must be of type int, string given -Warning: non-representable float %r(1\.4757395258967641E\+20|34359738352)%r was cast to int in %s on line %d +Warning: The float %r(1\.4757395258967641E\+20|34359738352)%r is not representable as an int, cast occurred in %s on line %d diff --git a/ext/opcache/tests/jit/add_011.phpt b/ext/opcache/tests/jit/add_011.phpt index 5812f926961ee..17bd7be99d157 100644 --- a/ext/opcache/tests/jit/add_011.phpt +++ b/ext/opcache/tests/jit/add_011.phpt @@ -195,6 +195,6 @@ int(-9223371969208523780) Warning: Undefined variable $u in %sadd_011.php on line 5 -Warning: non-representable float %f was cast to int in %sadd_011.php on line 5 +Warning: The float %f is not representable as an int, cast occurred in %sadd_011.php on line 5 int(66572500992) diff --git a/ext/opcache/tests/jit/array_elem_002.phpt b/ext/opcache/tests/jit/array_elem_002.phpt index d3d2732f0d4d8..01de92acfccf8 100644 --- a/ext/opcache/tests/jit/array_elem_002.phpt +++ b/ext/opcache/tests/jit/array_elem_002.phpt @@ -11,7 +11,7 @@ $string_float= PHP_INT_MAX; $a = [$float => 'a', $string_float => 'b', 'c', 'd']; ?> --EXPECTF-- -Warning: non-representable float 1.0E+38 was cast to int in %sarray_elem_002.php on line 4 +Warning: The float 1.0E+38 is not representable as an int, cast occurred in %sarray_elem_002.php on line 4 Fatal error: Uncaught Error: Cannot add element to the array as the next element is already occupied in %sarray_elem_002.php:4 Stack trace: diff --git a/ext/opcache/tests/jit/gh19669-001.phpt b/ext/opcache/tests/jit/gh19669-001.phpt index af92eb3f4f66f..e8c54c542c83c 100644 --- a/ext/opcache/tests/jit/gh19669-001.phpt +++ b/ext/opcache/tests/jit/gh19669-001.phpt @@ -21,5 +21,5 @@ function test() { var_dump(test()); ?> --EXPECTF-- -Warning: non-representable float -1.8446744073709552E+19 was cast to int in %s on line %d +Warning: The float -1.8446744073709552E+19 is not representable as an int, cast occurred in %s on line %d int(-3) diff --git a/ext/opcache/tests/jit/gh19669-002.phpt b/ext/opcache/tests/jit/gh19669-002.phpt index 0465420b2fd64..3a1aa0aa958c9 100644 --- a/ext/opcache/tests/jit/gh19669-002.phpt +++ b/ext/opcache/tests/jit/gh19669-002.phpt @@ -21,5 +21,5 @@ function test() { var_dump(test()); ?> --EXPECTF-- -Warning: non-representable float -1.8446744073709552E+19 was cast to int in %s on line %d +Warning: The float -1.8446744073709552E+19 is not representable as an int, cast occurred in %s on line %d int(-10) diff --git a/ext/opcache/tests/jit/reg_alloc_003_32bits.phpt b/ext/opcache/tests/jit/reg_alloc_003_32bits.phpt index aaca14518ffd3..ecef070c3f2f5 100644 --- a/ext/opcache/tests/jit/reg_alloc_003_32bits.phpt +++ b/ext/opcache/tests/jit/reg_alloc_003_32bits.phpt @@ -23,5 +23,5 @@ function test($char_code) { echo test(65), "\n"; ?> --EXPECTF-- -Warning: non-representable float 4294967168 was cast to int in %s on line %d +Warning: The float 4294967168 is not representable as an int, cast occurred in %s on line %d correct diff --git a/ext/standard/tests/general_functions/gettype_settype_variation2.phpt b/ext/standard/tests/general_functions/gettype_settype_variation2.phpt index 25152e8288c34..bdbf3de174ac1 100644 --- a/ext/standard/tests/general_functions/gettype_settype_variation2.phpt +++ b/ext/standard/tests/general_functions/gettype_settype_variation2.phpt @@ -274,7 +274,7 @@ int(1) string(7) "integer" -- Iteration 20 -- string(6) "string" -2: non-representable float-string 2.974394749328742E+21 was cast to int +2: The float-string 2.974394749328742E+21 is not representable as an int, cast occurred bool(true) int(2147483647) string(7) "integer" @@ -305,7 +305,7 @@ int(1) string(7) "integer" -- Iteration 26 -- string(6) "string" -2: non-representable float-string 2.974394749328742E+21 was cast to int +2: The float-string 2.974394749328742E+21 is not representable as an int, cast occurred bool(true) int(2147483647) string(7) "integer" @@ -426,13 +426,13 @@ int(2147483647) string(7) "integer" -- Iteration 50 -- string(6) "double" -2: non-representable float 2147483649 was cast to int +2: The float 2147483649 is not representable as an int, cast occurred bool(true) int(-2147483647) string(7) "integer" -- Iteration 51 -- string(6) "double" -2: non-representable float 1232147483649 was cast to int +2: The float 1232147483649 is not representable as an int, cast occurred bool(true) int(-508130303) string(7) "integer" @@ -443,7 +443,7 @@ int(85) string(7) "integer" -- Iteration 53 -- string(6) "double" -2: non-representable float 1058513956921 was cast to int +2: The float 1058513956921 is not representable as an int, cast occurred bool(true) int(1952002105) string(7) "integer" @@ -464,7 +464,7 @@ int(-365) string(7) "integer" -- Iteration 57 -- string(6) "double" -2: non-representable float 80561044571754 was cast to int +2: The float 80561044571754 is not representable as an int, cast occurred bool(true) int(343000682) string(7) "integer" @@ -675,7 +675,7 @@ int(1) string(7) "integer" -- Iteration 20 -- string(6) "string" -2: non-representable float-string 2.974394749328742E+21 was cast to int +2: The float-string 2.974394749328742E+21 is not representable as an int, cast occurred bool(true) int(2147483647) string(7) "integer" @@ -706,7 +706,7 @@ int(1) string(7) "integer" -- Iteration 26 -- string(6) "string" -2: non-representable float-string 2.974394749328742E+21 was cast to int +2: The float-string 2.974394749328742E+21 is not representable as an int, cast occurred bool(true) int(2147483647) string(7) "integer" @@ -827,13 +827,13 @@ int(2147483647) string(7) "integer" -- Iteration 50 -- string(6) "double" -2: non-representable float 2147483649 was cast to int +2: The float 2147483649 is not representable as an int, cast occurred bool(true) int(-2147483647) string(7) "integer" -- Iteration 51 -- string(6) "double" -2: non-representable float 1232147483649 was cast to int +2: The float 1232147483649 is not representable as an int, cast occurred bool(true) int(-508130303) string(7) "integer" @@ -844,7 +844,7 @@ int(85) string(7) "integer" -- Iteration 53 -- string(6) "double" -2: non-representable float 1058513956921 was cast to int +2: The float 1058513956921 is not representable as an int, cast occurred bool(true) int(1952002105) string(7) "integer" @@ -865,7 +865,7 @@ int(-365) string(7) "integer" -- Iteration 57 -- string(6) "double" -2: non-representable float 80561044571754 was cast to int +2: The float 80561044571754 is not representable as an int, cast occurred bool(true) int(343000682) string(7) "integer" diff --git a/ext/standard/tests/general_functions/intval.phpt b/ext/standard/tests/general_functions/intval.phpt index 1a2549c115ffe..3d8fa2f4ff8cc 100644 --- a/ext/standard/tests/general_functions/intval.phpt +++ b/ext/standard/tests/general_functions/intval.phpt @@ -222,18 +222,18 @@ int(2147483647) *** Testing intval() on non integer types *** -Warning: non-representable float-string -2147483649 was cast to int in %s on line %d +Warning: The float-string -2147483649 is not representable as an int, cast occurred in %s on line %d int(-2147483648) -Warning: non-representable float-string 2147483648 was cast to int in %s on line %d +Warning: The float-string 2147483648 is not representable as an int, cast occurred in %s on line %d int(2147483647) int(0) int(0) -Warning: non-representable float-string 20000000001 was cast to int in %s on line %d +Warning: The float-string 20000000001 is not representable as an int, cast occurred in %s on line %d int(2147483647) -Warning: non-representable float-string -20000000001 was cast to int in %s on line %d +Warning: The float-string -20000000001 is not representable as an int, cast occurred in %s on line %d int(-2147483648) int(0) int(0) diff --git a/ext/standard/tests/math/bug30695.phpt b/ext/standard/tests/math/bug30695.phpt index 71bc39bdc316e..a2ac79c112629 100644 --- a/ext/standard/tests/math/bug30695.phpt +++ b/ext/standard/tests/math/bug30695.phpt @@ -53,22 +53,22 @@ if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only"); echo "\n", toUTF8(65), "\n", toUTF8(233), "\n", toUTF8(1252), "\n", toUTF8(20095), "\n"; ?> --EXPECTF-- -Warning: non-representable float 4294967168 was cast to int in %s on line %d +Warning: The float 4294967168 is not representable as an int, cast occurred in %s on line %d A -Warning: non-representable float 4294967168 was cast to int in %s on line %d +Warning: The float 4294967168 is not representable as an int, cast occurred in %s on line %d -Warning: non-representable float 4294965248 was cast to int in %s on line %d +Warning: The float 4294965248 is not representable as an int, cast occurred in %s on line %d é -Warning: non-representable float 4294967168 was cast to int in %s on line %d +Warning: The float 4294967168 is not representable as an int, cast occurred in %s on line %d -Warning: non-representable float 4294965248 was cast to int in %s on line %d +Warning: The float 4294965248 is not representable as an int, cast occurred in %s on line %d Ӥ -Warning: non-representable float 4294967168 was cast to int in %s on line %d +Warning: The float 4294967168 is not representable as an int, cast occurred in %s on line %d -Warning: non-representable float 4294965248 was cast to int in %s on line %d +Warning: The float 4294965248 is not representable as an int, cast occurred in %s on line %d -Warning: non-representable float 4294901760 was cast to int in %s on line %d +Warning: The float 4294901760 is not representable as an int, cast occurred in %s on line %d 乿 diff --git a/ext/standard/tests/strings/bug47842.phpt b/ext/standard/tests/strings/bug47842.phpt index 22b62560bc433..1c8da881e7ced 100644 --- a/ext/standard/tests/strings/bug47842.phpt +++ b/ext/standard/tests/strings/bug47842.phpt @@ -31,6 +31,6 @@ sscanf 64-bit signed int '9223372036854775807' (2^63)-1 = 9223372036854775807 sscanf 64-bit unsign int '18446744073709551615' (2^64)-1 = 18446744073709551615 printf 64-bit signed int '9223372036854775807' (2^63)-1 = 9223372036854775807 -Warning: non-representable float 1.8446744073709552E+19 was cast to int in %s on line %d +Warning: The float 1.8446744073709552E+19 is not representable as an int, cast occurred in %s on line %d printf 64-bit signed int '18446744073709551615' (2^64)-1 = 0 Done diff --git a/ext/standard/tests/strings/pack.phpt b/ext/standard/tests/strings/pack.phpt index 643f023509cc4..e71f9ce37a964 100644 --- a/ext/standard/tests/strings/pack.phpt +++ b/ext/standard/tests/strings/pack.phpt @@ -144,13 +144,13 @@ Array [1] => -64434 ) -Warning: non-representable float 4294967296 was cast to int in %s on line %d +Warning: The float 4294967296 is not representable as an int, cast occurred in %s on line %d Array ( [1] => 0 ) -Warning: non-representable float -4294967296 was cast to int in %s on line %d +Warning: The float -4294967296 is not representable as an int, cast occurred in %s on line %d Array ( [1] => 0 @@ -164,13 +164,13 @@ Array [1] => 0 ) -Warning: non-representable float 2147483650 was cast to int in %s on line %d +Warning: The float 2147483650 is not representable as an int, cast occurred in %s on line %d Array ( [1] => -2147483646 ) -Warning: non-representable float 4294967295 was cast to int in %s on line %d +Warning: The float 4294967295 is not representable as an int, cast occurred in %s on line %d Array ( [1] => -1 @@ -188,13 +188,13 @@ Array [1] => 0 ) -Warning: non-representable float 2147483650 was cast to int in %s on line %d +Warning: The float 2147483650 is not representable as an int, cast occurred in %s on line %d Array ( [1] => -2147483646 ) -Warning: non-representable float 4294967296 was cast to int in %s on line %d +Warning: The float 4294967296 is not representable as an int, cast occurred in %s on line %d Array ( [1] => 0 @@ -240,13 +240,13 @@ Array [1] => 0 ) -Warning: non-representable float 2147483650 was cast to int in %s on line %d +Warning: The float 2147483650 is not representable as an int, cast occurred in %s on line %d Array ( [1] => -2147483646 ) -Warning: non-representable float 4294967296 was cast to int in %s on line %d +Warning: The float 4294967296 is not representable as an int, cast occurred in %s on line %d Array ( [1] => 0 @@ -316,13 +316,13 @@ Array [1] => 0 ) -Warning: non-representable float 2147483650 was cast to int in %s on line %d +Warning: The float 2147483650 is not representable as an int, cast occurred in %s on line %d Array ( [1] => -2147483646 ) -Warning: non-representable float 4294967296 was cast to int in %s on line %d +Warning: The float 4294967296 is not representable as an int, cast occurred in %s on line %d Array ( [1] => 0 diff --git a/ext/standard/tests/strings/pack64.phpt b/ext/standard/tests/strings/pack64.phpt index 0f492bc6e5efe..238195287b2b2 100644 --- a/ext/standard/tests/strings/pack64.phpt +++ b/ext/standard/tests/strings/pack64.phpt @@ -47,7 +47,7 @@ Array [1] => 0 ) -Warning: non-representable float 9.223372036854776E+18 was cast to int in %s on line %d +Warning: The float 9.223372036854776E+18 is not representable as an int, cast occurred in %s on line %d Array ( [1] => -9223372036854775808 @@ -57,7 +57,7 @@ Array [1] => -1 ) -Warning: non-representable float 9.223372036854776E+18 was cast to int in %s on line %d +Warning: The float 9.223372036854776E+18 is not representable as an int, cast occurred in %s on line %d Array ( [1] => -9223372036854775808 @@ -71,7 +71,7 @@ Array [1] => 0 ) -Warning: non-representable float 9.223372036854776E+18 was cast to int in %s on line %d +Warning: The float 9.223372036854776E+18 is not representable as an int, cast occurred in %s on line %d Array ( [1] => -9223372036854775808 @@ -81,7 +81,7 @@ Array [1] => -1 ) -Warning: non-representable float 9.223372036854776E+18 was cast to int in %s on line %d +Warning: The float 9.223372036854776E+18 is not representable as an int, cast occurred in %s on line %d Array ( [1] => -9223372036854775808 @@ -95,7 +95,7 @@ Array [1] => 0 ) -Warning: non-representable float 9.223372036854776E+18 was cast to int in %s on line %d +Warning: The float 9.223372036854776E+18 is not representable as an int, cast occurred in %s on line %d Array ( [1] => -9223372036854775808 @@ -105,7 +105,7 @@ Array [1] => -1 ) -Warning: non-representable float 9.223372036854776E+18 was cast to int in %s on line %d +Warning: The float 9.223372036854776E+18 is not representable as an int, cast occurred in %s on line %d Array ( [1] => -9223372036854775808 @@ -119,7 +119,7 @@ Array [1] => 0 ) -Warning: non-representable float 9.223372036854776E+18 was cast to int in %s on line %d +Warning: The float 9.223372036854776E+18 is not representable as an int, cast occurred in %s on line %d Array ( [1] => -9223372036854775808 @@ -129,7 +129,7 @@ Array [1] => -1 ) -Warning: non-representable float 9.223372036854776E+18 was cast to int in %s on line %d +Warning: The float 9.223372036854776E+18 is not representable as an int, cast occurred in %s on line %d Array ( [1] => -9223372036854775808 diff --git a/ext/standard/tests/strings/vprintf_variation12.phpt b/ext/standard/tests/strings/vprintf_variation12.phpt index 157aacb41de21..f2e4270af3100 100644 --- a/ext/standard/tests/strings/vprintf_variation12.phpt +++ b/ext/standard/tests/strings/vprintf_variation12.phpt @@ -79,11 +79,11 @@ foreach($args_array as $args) { -- Iteration 1 -- -Warning: non-representable float 20000000000 was cast to int in %s on line %d +Warning: The float 20000000000 is not representable as an int, cast occurred in %s on line %d -Warning: non-representable float 2000000000000 was cast to int in %s on line %d +Warning: The float 2000000000000 is not representable as an int, cast occurred in %s on line %d -Warning: non-representable float 22000000000000 was cast to int in %s on line %d +Warning: The float 22000000000000 is not representable as an int, cast occurred in %s on line %d 2 0 12 361100 37777775456 2322 diff --git a/ext/standard/tests/strings/vprintf_variation14.phpt b/ext/standard/tests/strings/vprintf_variation14.phpt index c273224f6939d..4bda95917770a 100644 --- a/ext/standard/tests/strings/vprintf_variation14.phpt +++ b/ext/standard/tests/strings/vprintf_variation14.phpt @@ -80,11 +80,11 @@ foreach($args_array as $args) { -- Iteration 1 -- -Warning: non-representable float 20000000000 was cast to int in %s on line %d +Warning: The float 20000000000 is not representable as an int, cast occurred in %s on line %d -Warning: non-representable float 2000000000000 was cast to int in %s on line %d +Warning: The float 2000000000000 is not representable as an int, cast occurred in %s on line %d -Warning: non-representable float 22000000000000 was cast to int in %s on line %d +Warning: The float 22000000000000 is not representable as an int, cast occurred in %s on line %d 2 0 a 1e240 x fffffb2e 4d2 diff --git a/ext/standard/tests/strings/vprintf_variation15.phpt b/ext/standard/tests/strings/vprintf_variation15.phpt index c1898564ae97d..2eda443ebb95f 100644 --- a/ext/standard/tests/strings/vprintf_variation15.phpt +++ b/ext/standard/tests/strings/vprintf_variation15.phpt @@ -53,13 +53,13 @@ int(16) -- Iteration 2 -- -Warning: non-representable float 12345678900 was cast to int in %s on line %d +Warning: The float 12345678900 is not representable as an int, cast occurred in %s on line %d 3755744308 1234 12345 int(21) -- Iteration 3 -- -Warning: non-representable float 101234567000 was cast to int in %s on line %d +Warning: The float 101234567000 is not representable as an int, cast occurred in %s on line %d 1234000 2450319192 120 int(25) diff --git a/ext/standard/tests/strings/vprintf_variation15_64bit.phpt b/ext/standard/tests/strings/vprintf_variation15_64bit.phpt index 1494272784544..0ccb490095aac 100644 --- a/ext/standard/tests/strings/vprintf_variation15_64bit.phpt +++ b/ext/standard/tests/strings/vprintf_variation15_64bit.phpt @@ -57,7 +57,7 @@ int(22) -- Iteration 3 -- -Warning: non-representable float 1.0E+21 was cast to int in %s on line %d +Warning: The float 1.0E+21 is not representable as an int, cast occurred in %s on line %d 1234000 3875820019684212736 120 int(34) diff --git a/ext/standard/tests/strings/vprintf_variation16.phpt b/ext/standard/tests/strings/vprintf_variation16.phpt index 73ab1b5d326bd..c064b7c4f0c78 100644 --- a/ext/standard/tests/strings/vprintf_variation16.phpt +++ b/ext/standard/tests/strings/vprintf_variation16.phpt @@ -71,11 +71,11 @@ foreach($args_array as $args) { -- Iteration 1 -- -Warning: non-representable float 20000000000 was cast to int in %s on line %d +Warning: The float 20000000000 is not representable as an int, cast occurred in %s on line %d -Warning: non-representable float 2000000000000 was cast to int in %s on line %d +Warning: The float 2000000000000 is not representable as an int, cast occurred in %s on line %d -Warning: non-representable float 22000000000000 was cast to int in %s on line %d +Warning: The float 22000000000000 is not representable as an int, cast occurred in %s on line %d 2 0 10 123456 123456 1234 2820130816 2840207360 1177509888 diff --git a/ext/standard/tests/strings/vprintf_variation4.phpt b/ext/standard/tests/strings/vprintf_variation4.phpt index 1badcfb83423b..96836f83ee618 100644 --- a/ext/standard/tests/strings/vprintf_variation4.phpt +++ b/ext/standard/tests/strings/vprintf_variation4.phpt @@ -72,7 +72,7 @@ foreach($args_array as $args) { -- Iteration 1 -- -Warning: non-representable float 20000000000 was cast to int in %s on line %d +Warning: The float 20000000000 is not representable as an int, cast occurred in %s on line %d 2 +0 10 123456 -1234 1234 -1474836480 200000 4000 22000000 diff --git a/tests/lang/bug27354.phpt b/tests/lang/bug27354.phpt index 89efed29ac6f7..e3cac1b170238 100644 --- a/tests/lang/bug27354.phpt +++ b/tests/lang/bug27354.phpt @@ -10,7 +10,7 @@ var_dump(-2147483648 % -2); --EXPECTF-- int(0) -Warning: non-representable float -9.223372036860776E+18 was cast to int in %s on line %d +Warning: The float -9.223372036860776E+18 is not representable as an int, cast occurred in %s on line %d int(0) int(0) int(0) diff --git a/tests/lang/operators/bitwiseNot_basiclong_64bit.phpt b/tests/lang/operators/bitwiseNot_basiclong_64bit.phpt index 583b5c070aafb..1a1105a557a35 100644 --- a/tests/lang/operators/bitwiseNot_basiclong_64bit.phpt +++ b/tests/lang/operators/bitwiseNot_basiclong_64bit.phpt @@ -52,7 +52,7 @@ int(-4294967294) int(-9223372036854775807) --- testing: 9.2233720368548E+18 --- -Warning: non-representable float 9.223372036854776E+18 was cast to int in %s on line %d +Warning: The float 9.223372036854776E+18 is not representable as an int, cast occurred in %s on line %d int(9223372036854775807) --- testing: -9223372036854775807 --- int(9223372036854775806) From f75490918636ab17df6be63eab896517e2a1db53 Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Sun, 21 Sep 2025 22:47:15 +0100 Subject: [PATCH 7/8] Pass actual string for float-string --- .../float_to_int/explicit_casts_should_not_warn.phpt | 4 ++-- .../float_to_int/non-rep-float-as-int-extra1.phpt | 2 +- .../warning_float_does_not_fit_zend_long_arrays.phpt | 2 +- .../warning_float_does_not_fit_zend_long_strings.phpt | 2 +- Zend/zend_operators.c | 8 ++++---- Zend/zend_operators.h | 8 ++++---- ext/dom/php_dom.c | 2 +- .../general_functions/gettype_settype_variation2.phpt | 8 ++++---- ext/standard/tests/general_functions/intval.phpt | 8 ++++---- 9 files changed, 22 insertions(+), 22 deletions(-) diff --git a/Zend/tests/type_coercion/float_to_int/explicit_casts_should_not_warn.phpt b/Zend/tests/type_coercion/float_to_int/explicit_casts_should_not_warn.phpt index 5566b10b0a333..2b876597b9b1e 100644 --- a/Zend/tests/type_coercion/float_to_int/explicit_casts_should_not_warn.phpt +++ b/Zend/tests/type_coercion/float_to_int/explicit_casts_should_not_warn.phpt @@ -40,9 +40,9 @@ int(0) int(3) int(3) -Warning: The float-string 1.0E+121 is not representable as an int, cast occurred in %s on line %d +Warning: The float-string "1.0E+121" is not representable as an int, cast occurred in %s on line %d int(9223372036854775807) -Warning: The float-string 1.0E+301 is not representable as an int, cast occurred in %s on line %d +Warning: The float-string "1.0E+301" is not representable as an int, cast occurred in %s on line %d int(9223372036854775807) int(0) diff --git a/Zend/tests/type_coercion/float_to_int/non-rep-float-as-int-extra1.phpt b/Zend/tests/type_coercion/float_to_int/non-rep-float-as-int-extra1.phpt index 1fb6f4efc45c0..aacf0dc855190 100644 --- a/Zend/tests/type_coercion/float_to_int/non-rep-float-as-int-extra1.phpt +++ b/Zend/tests/type_coercion/float_to_int/non-rep-float-as-int-extra1.phpt @@ -14,6 +14,6 @@ var_dump($b | 1); ?> --EXPECTF-- -The float-string 1.0E+4%d is not representable as an int, cast occurred +The float-string "1.0E+4%d" is not representable as an int, cast occurred Implicit conversion from float-string "1.0E+4%d" to int loses precision int(%d) diff --git a/Zend/tests/type_coercion/float_to_int/warning_float_does_not_fit_zend_long_arrays.phpt b/Zend/tests/type_coercion/float_to_int/warning_float_does_not_fit_zend_long_arrays.phpt index d707e2dc311c3..779e103e6f821 100644 --- a/Zend/tests/type_coercion/float_to_int/warning_float_does_not_fit_zend_long_arrays.phpt +++ b/Zend/tests/type_coercion/float_to_int/warning_float_does_not_fit_zend_long_arrays.phpt @@ -26,7 +26,7 @@ var_dump($array[$string_float]); Warning: The float 1.0E+121 is not representable as an int, cast occurred in %s on line %d int(0) -Warning: The float-string 1.0E+121 is not representable as an int, cast occurred in %s on line %d +Warning: The float-string "1.0E+121" is not representable as an int, cast occurred in %s on line %d bool(true) Warning: The float 1.0E+121 is not representable as an int, cast occurred in %s on line %d diff --git a/Zend/tests/type_coercion/float_to_int/warning_float_does_not_fit_zend_long_strings.phpt b/Zend/tests/type_coercion/float_to_int/warning_float_does_not_fit_zend_long_strings.phpt index 5cba01392afed..b4651d28ac4b3 100644 --- a/Zend/tests/type_coercion/float_to_int/warning_float_does_not_fit_zend_long_strings.phpt +++ b/Zend/tests/type_coercion/float_to_int/warning_float_does_not_fit_zend_long_strings.phpt @@ -78,7 +78,7 @@ var_dump($string); Warning: The float 1.0E+121 is not representable as an int, cast occurred in %s on line %d int(0) -Warning: The float-string 1.0E+121 is not representable as an int, cast occurred in %s on line %d +Warning: The float-string "1.0E+121" is not representable as an int, cast occurred in %s on line %d int(9223372036854775807) Attempt to read Float diff --git a/Zend/zend_operators.c b/Zend/zend_operators.c index fdfce495aed0f..91421b45fdf31 100644 --- a/Zend/zend_operators.c +++ b/Zend/zend_operators.c @@ -431,7 +431,7 @@ static zend_never_inline zend_long ZEND_FASTCALL zendi_try_get_long(const zval * /* zend_dval_to_lval_cap() can emit a warning so always do the copy here */ op_str = zend_string_copy(Z_STR_P(op)); } - lval = zend_dval_to_lval_cap(dval); + lval = zend_dval_to_lval_cap(dval, op_str); if (!zend_is_long_compatible(dval, lval)) { zend_incompatible_string_to_long_error(op_str); if (UNEXPECTED(EG(exception))) { @@ -918,9 +918,9 @@ ZEND_API void ZEND_COLD zend_oob_double_to_long_error(double d) { zend_error_unchecked(E_WARNING, "The float %.*H is not representable as an int, cast occurred", -1, d); } -ZEND_API void ZEND_COLD zend_oob_string_to_long_error(double d) +ZEND_API void ZEND_COLD zend_oob_string_to_long_error(const zend_string *s) { - zend_error_unchecked(E_WARNING, "The float-string %.*H is not representable as an int, cast occurred", -1, d); + zend_error_unchecked(E_WARNING, "The float-string \"%s\" is not representable as an int, cast occurred", ZSTR_VAL(s)); } ZEND_API zend_long ZEND_FASTCALL zval_get_long_func(const zval *op, bool is_strict) /* {{{ */ @@ -963,7 +963,7 @@ ZEND_API zend_long ZEND_FASTCALL zval_get_long_func(const zval *op, bool is_stri * behaviour. */ /* Most usages are expected to not be (int) casts */ - lval = zend_dval_to_lval_cap(dval); + lval = zend_dval_to_lval_cap(dval, Z_STR_P(op)); if (UNEXPECTED(is_strict)) { if (!zend_is_long_compatible(dval, lval)) { zend_incompatible_string_to_long_error(Z_STR_P(op)); diff --git a/Zend/zend_operators.h b/Zend/zend_operators.h index ef48014684a5b..e821827f57f58 100644 --- a/Zend/zend_operators.h +++ b/Zend/zend_operators.h @@ -118,7 +118,7 @@ ZEND_API const char* ZEND_FASTCALL zend_memnrstr_ex(const char *haystack, const 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_COLD zend_oob_double_to_long_error(double d); -ZEND_API void ZEND_COLD zend_oob_string_to_long_error(double d); +ZEND_API void ZEND_COLD zend_oob_string_to_long_error(const zend_string *s); ZEND_API zend_long ZEND_FASTCALL zend_dval_to_lval_slow(double d); @@ -145,13 +145,13 @@ static zend_always_inline zend_long zend_dval_to_lval_silent(double d) } /* Used to convert a string float to integer during an (int) cast */ -static zend_always_inline zend_long zend_dval_to_lval_cap(double d) +static zend_always_inline zend_long zend_dval_to_lval_cap(double d, const zend_string *s) { if (UNEXPECTED(!zend_finite(d))) { - zend_oob_string_to_long_error(d); + zend_oob_string_to_long_error(s); return 0; } else if (!ZEND_DOUBLE_FITS_LONG(d)) { - zend_oob_string_to_long_error(d); + zend_oob_string_to_long_error(s); return (d > 0 ? ZEND_LONG_MAX : ZEND_LONG_MIN); } return (zend_long)d; diff --git a/ext/dom/php_dom.c b/ext/dom/php_dom.c index ee99f97f35455..095d07e875ea9 100644 --- a/ext/dom/php_dom.c +++ b/ext/dom/php_dom.c @@ -2261,7 +2261,7 @@ static bool dom_nodemap_or_nodelist_process_offset_as_named(zval *offset, zend_l if (0 == (is_numeric_string_type = is_numeric_string(Z_STRVAL_P(offset), Z_STRLEN_P(offset), lval, &dval, true))) { return true; } else if (is_numeric_string_type == IS_DOUBLE) { - *lval = zend_dval_to_lval_cap(dval); + *lval = zend_dval_to_lval_cap(dval, Z_STR_P(offset)); } } else { *lval = zval_get_long(offset); diff --git a/ext/standard/tests/general_functions/gettype_settype_variation2.phpt b/ext/standard/tests/general_functions/gettype_settype_variation2.phpt index bdbf3de174ac1..5f35d713d512f 100644 --- a/ext/standard/tests/general_functions/gettype_settype_variation2.phpt +++ b/ext/standard/tests/general_functions/gettype_settype_variation2.phpt @@ -274,7 +274,7 @@ int(1) string(7) "integer" -- Iteration 20 -- string(6) "string" -2: The float-string 2.974394749328742E+21 is not representable as an int, cast occurred +2: The float-string "2974394749328742328432" is not representable as an int, cast occurred bool(true) int(2147483647) string(7) "integer" @@ -305,7 +305,7 @@ int(1) string(7) "integer" -- Iteration 26 -- string(6) "string" -2: The float-string 2.974394749328742E+21 is not representable as an int, cast occurred +2: The float-string "2974394749328742328432" is not representable as an int, cast occurred bool(true) int(2147483647) string(7) "integer" @@ -675,7 +675,7 @@ int(1) string(7) "integer" -- Iteration 20 -- string(6) "string" -2: The float-string 2.974394749328742E+21 is not representable as an int, cast occurred +2: The float-string "2974394749328742328432" is not representable as an int, cast occurred bool(true) int(2147483647) string(7) "integer" @@ -706,7 +706,7 @@ int(1) string(7) "integer" -- Iteration 26 -- string(6) "string" -2: The float-string 2.974394749328742E+21 is not representable as an int, cast occurred +2: The float-string "2974394749328742328432" is not representable as an int, cast occurred bool(true) int(2147483647) string(7) "integer" diff --git a/ext/standard/tests/general_functions/intval.phpt b/ext/standard/tests/general_functions/intval.phpt index 3d8fa2f4ff8cc..dbfb4a58eda93 100644 --- a/ext/standard/tests/general_functions/intval.phpt +++ b/ext/standard/tests/general_functions/intval.phpt @@ -222,18 +222,18 @@ int(2147483647) *** Testing intval() on non integer types *** -Warning: The float-string -2147483649 is not representable as an int, cast occurred in %s on line %d +Warning: The float-string "-2147483649" is not representable as an int, cast occurred in %s on line %d int(-2147483648) -Warning: The float-string 2147483648 is not representable as an int, cast occurred in %s on line %d +Warning: The float-string "2147483648" is not representable as an int, cast occurred in %s on line %d int(2147483647) int(0) int(0) -Warning: The float-string 20000000001 is not representable as an int, cast occurred in %s on line %d +Warning: The float-string "20000000001" is not representable as an int, cast occurred in %s on line %d int(2147483647) -Warning: The float-string -20000000001 is not representable as an int, cast occurred in %s on line %d +Warning: The float-string "-20000000001" is not representable as an int, cast occurred in %s on line %d int(-2147483648) int(0) int(0) From 3005005b4cf875752ff35d542a09059fce6ae0ae Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Sun, 21 Sep 2025 23:08:03 +0100 Subject: [PATCH 8/8] Fix missing tests --- .../float_to_int/explicit_casts_should_not_warn_32bit.phpt | 4 ++-- .../warning_float_does_not_fit_zend_long_strings_32bit.phpt | 2 +- ext/standard/tests/general_functions/intval.phpt | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Zend/tests/type_coercion/float_to_int/explicit_casts_should_not_warn_32bit.phpt b/Zend/tests/type_coercion/float_to_int/explicit_casts_should_not_warn_32bit.phpt index 3c90f0fd4d9c9..b34e762dfff35 100644 --- a/Zend/tests/type_coercion/float_to_int/explicit_casts_should_not_warn_32bit.phpt +++ b/Zend/tests/type_coercion/float_to_int/explicit_casts_should_not_warn_32bit.phpt @@ -40,9 +40,9 @@ int(0) int(3) int(3) -Warning: The float-string 1.0E+121 is not representable as an int, cast occurred in %s on line %d +Warning: The float-string "1.0E+121" is not representable as an int, cast occurred in %s on line %d int(2147483647) -Warning: The float-string 1.0E+301 is not representable as an int, cast occurred in %s on line %d +Warning: The float-string "1.0E+301" is not representable as an int, cast occurred in %s on line %d int(2147483647) int(0) diff --git a/Zend/tests/type_coercion/float_to_int/warning_float_does_not_fit_zend_long_strings_32bit.phpt b/Zend/tests/type_coercion/float_to_int/warning_float_does_not_fit_zend_long_strings_32bit.phpt index c610acfada01a..3ec2c62cacdd4 100644 --- a/Zend/tests/type_coercion/float_to_int/warning_float_does_not_fit_zend_long_strings_32bit.phpt +++ b/Zend/tests/type_coercion/float_to_int/warning_float_does_not_fit_zend_long_strings_32bit.phpt @@ -78,7 +78,7 @@ var_dump($string); Warning: The float 1.0E+121 is not representable as an int, cast occurred in %s on line %d int(0) -Warning: The float-string 1.0E+121 is not representable as an int, cast occurred in %s on line %d +Warning: The float-string "1.0E+121" is not representable as an int, cast occurred in %s on line %d int(2147483647) Attempt to read Float diff --git a/ext/standard/tests/general_functions/intval.phpt b/ext/standard/tests/general_functions/intval.phpt index dbfb4a58eda93..83377d85a099a 100644 --- a/ext/standard/tests/general_functions/intval.phpt +++ b/ext/standard/tests/general_functions/intval.phpt @@ -230,10 +230,10 @@ int(2147483647) int(0) int(0) -Warning: The float-string "20000000001" is not representable as an int, cast occurred in %s on line %d +Warning: The float-string "020000000001" is not representable as an int, cast occurred in %s on line %d int(2147483647) -Warning: The float-string "-20000000001" is not representable as an int, cast occurred in %s on line %d +Warning: The float-string "-020000000001" is not representable as an int, cast occurred in %s on line %d int(-2147483648) int(0) int(0)