Browse Source
core: Warn when non-representable floats are coerced to int (#19760)
core: Warn when non-representable floats are coerced to int (#19760)
RFC: https://wiki.php.net/rfc/warnings-php-8-5#casting_out_of_range_floats_to_intpull/19447/head
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
62 changed files with 1107 additions and 275 deletions
-
6Zend/Optimizer/sccp.c
-
1Zend/Optimizer/zend_inference.c
-
2Zend/tests/bitwise_not_precision_exception.phpt
-
10Zend/tests/bug46701.phpt
-
2Zend/tests/bug78340.phpt
-
2Zend/tests/falsetoarray_003.phpt
-
11Zend/tests/int_overflow_32bit.phpt
-
8Zend/tests/int_overflow_64bit.phpt
-
10Zend/tests/int_underflow_32bit.phpt
-
89Zend/tests/offsets/ArrayObject_container_offset_behaviour.phpt
-
89Zend/tests/offsets/array_container_offset_behaviour.phpt
-
0Zend/tests/offsets/array_offset.phpt
-
2Zend/tests/offsets/array_offset_002.phpt
-
89Zend/tests/offsets/false_container_offset_behaviour.phpt
-
87Zend/tests/offsets/null_container_offset_behaviour.phpt
-
95Zend/tests/offsets/string_container_offset_behaviour.phpt
-
2Zend/tests/offsets/test_offset_helpers.inc
-
2Zend/tests/runtime_compile_time_binary_operands.phpt
-
13Zend/tests/type_coercion/float_to_int/dval_to_lval_32.phpt
-
11Zend/tests/type_coercion/float_to_int/dval_to_lval_64.phpt
-
14Zend/tests/type_coercion/float_to_int/explicit_casts_should_not_warn.phpt
-
12Zend/tests/type_coercion/float_to_int/explicit_casts_should_not_warn_32bit.phpt
-
19Zend/tests/type_coercion/float_to_int/non-rep-float-as-int-extra1.phpt
-
17Zend/tests/type_coercion/float_to_int/non-rep-float-as-int-extra2.phpt
-
18Zend/tests/type_coercion/float_to_int/non-rep-float-as-int-extra3.phpt
-
18Zend/tests/type_coercion/float_to_int/non-rep-float-as-int-extra4.phpt
-
11Zend/tests/type_coercion/float_to_int/warning_float_does_not_fit_zend_long_arrays.phpt
-
3Zend/tests/type_coercion/float_to_int/warning_float_does_not_fit_zend_long_strings.phpt
-
3Zend/tests/type_coercion/float_to_int/warning_float_does_not_fit_zend_long_strings_32bit.phpt
-
8Zend/tests/type_coercion/int_special_values.phpt
-
31Zend/zend_compile.c
-
86Zend/zend_execute.c
-
44Zend/zend_operators.c
-
30Zend/zend_operators.h
-
10Zend/zend_vm_def.h
-
120Zend/zend_vm_execute.h
-
1ext/date/tests/bug79015.phpt
-
2ext/dom/php_dom.c
-
2ext/intl/tests/gh13766.phpt
-
226ext/opcache/jit/zend_jit_helpers.c
-
5ext/opcache/tests/jit/add_011.phpt
-
2ext/opcache/tests/jit/array_elem_002.phpt
-
3ext/opcache/tests/jit/gh19669-001.phpt
-
3ext/opcache/tests/jit/gh19669-002.phpt
-
2ext/opcache/tests/jit/reg_alloc_003_32bits.phpt
-
3ext/openssl/tests/openssl_decrypt_basic.phpt
-
18ext/standard/array.c
-
12ext/standard/tests/general_functions/gettype_settype_variation2.phpt
-
24ext/standard/tests/general_functions/intval.phpt
-
16ext/standard/tests/math/bug30695.phpt
-
4ext/standard/tests/strings/bug47842.phpt
-
22ext/standard/tests/strings/pack.phpt
-
18ext/standard/tests/strings/pack64.phpt
-
8ext/standard/tests/strings/vprintf_variation12.phpt
-
8ext/standard/tests/strings/vprintf_variation14.phpt
-
6ext/standard/tests/strings/vprintf_variation15.phpt
-
4ext/standard/tests/strings/vprintf_variation15_64bit.phpt
-
8ext/standard/tests/strings/vprintf_variation16.phpt
-
4ext/standard/tests/strings/vprintf_variation4.phpt
-
2main/php_variables.c
-
2tests/lang/bug27354.phpt
-
2tests/lang/operators/bitwiseNot_basiclong_64bit.phpt
@ -0,0 +1,19 @@ |
|||
--TEST-- |
|||
Non rep float string to int conversions should not crash when modified |
|||
--FILE-- |
|||
<?php |
|||
set_error_handler(function ($errno, $errstr) { |
|||
global $b; |
|||
$b = null; |
|||
echo $errstr, "\n"; |
|||
}); |
|||
|
|||
$a = "1.0E+" . rand(40,42); |
|||
$b = &$a; |
|||
var_dump($b | 1); |
|||
|
|||
?> |
|||
--EXPECTF-- |
|||
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) |
@ -0,0 +1,17 @@ |
|||
--TEST-- |
|||
Non rep float string to int conversions should not crash when modified |
|||
--FILE-- |
|||
<?php |
|||
|
|||
set_error_handler(function ($errno, $errstr) { |
|||
global $ary; |
|||
$ary = null; |
|||
echo $errstr, "\n"; |
|||
}); |
|||
|
|||
$ary = [rand()]; |
|||
unset($ary[1.0E+42]); |
|||
|
|||
?> |
|||
--EXPECT-- |
|||
The float 1.0E+42 is not representable as an int, cast occurred |
@ -0,0 +1,18 @@ |
|||
--TEST-- |
|||
Non rep float string to int conversions should not crash when modified |
|||
--FILE-- |
|||
<?php |
|||
|
|||
set_error_handler(function ($errno, $errstr) { |
|||
global $ary; |
|||
$ary = null; |
|||
echo $errstr, "\n"; |
|||
}); |
|||
|
|||
$ary = [rand()]; |
|||
var_dump(isset($ary[1.0E+42])); |
|||
|
|||
?> |
|||
--EXPECT-- |
|||
The float 1.0E+42 is not representable as an int, cast occurred |
|||
bool(false) |
@ -0,0 +1,18 @@ |
|||
--TEST-- |
|||
Non rep float string to int conversions should not crash when modified |
|||
--FILE-- |
|||
<?php |
|||
|
|||
set_error_handler(function ($errno, $errstr) { |
|||
global $ary; |
|||
$ary = null; |
|||
echo $errstr, "\n"; |
|||
}); |
|||
|
|||
$ary = [rand()]; |
|||
var_dump(\array_key_exists(1.0E+42, $ary)); |
|||
|
|||
?> |
|||
--EXPECT-- |
|||
The float 1.0E+42 is not representable as an int, cast occurred |
|||
bool(false) |
Write
Preview
Loading…
Cancel
Save
Reference in new issue