-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[RFC] Warn on implicit float to int conversions. #6661
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
61 commits
Select commit
Hold shift + click to select a range
a70ae1b
Warn on implicit float to int conversions.
Girgias 6a0ddf8
Fix JIT
Girgias 48e3aca
Fix double deprecation notice in debug builds
Girgias f9be93d
Fix test
Girgias 74ab99c
Remove some ZPP checks
Girgias 4963bf3
Add incompatible float to deprecation message
Girgias d9f5730
Micro optimization
Girgias 342252b
Add test for negative 0
Girgias e411fa4
Fix more tests
Girgias d27a94f
Keep zval_get_long() similar to an (int) cast
Girgias 20dafcc
Rework is_long_compatible function
Girgias 139aa8f
Move SEPARATE_ARRAY below the check.
Girgias f319fe4
Flip is_lax to is_strict
Girgias 0d678bf
Make sprintf family of functions warn on incompatible float to int co…
Girgias d2ee140
intval() is like (int) cast
Girgias 8bacb86
Fix jit with incompatible float to long for isset
Girgias f226954
Extract float to int deprecation message into own function
Girgias 4913890
Rephrase deprecation message
Girgias f55772b
Use zend_error_unchecked() for deprecation message
Girgias e78f0ee
Use common function once more
Girgias 737c674
ct_eval should not emit notices
Girgias fbbb5e4
Fix some tests
Girgias 77c4f5b
Add a ZEND_API for linking
Girgias 6b23056
Fix compile time evaluation
Girgias bb5a746
Remove error_reporting after fixing compile time eval
Girgias f50f497
Fix test heading
Girgias c922dc9
Bailout if array key is float
Girgias d3ed467
Standardize error message for float-strings
Girgias 443a1d4
Clarify why we need to use (uint32_t)-1 and not 0
Girgias 37e04d2
Fix Win test
Girgias 61e3f94
Bit op and mod may throw
Girgias 8854e74
Fix inference of zend_may_throw
Girgias 25e46f1
Attempt to fix JIT
Girgias f739178
Revert "Attempt to fix JIT"
Girgias af16894
Make printf() test not spit random bytes to debug on 32bits
Girgias 02fbb29
Update test after fix in core
Girgias 017bb20
Fix more 32bits tests
Girgias 45b68b6
Revert test change from 32bit
Girgias fad5644
Fix pass optimizer
Girgias eae1e65
Optimizer fixes and partial revert
Girgias fee33db
Fix zend_is_long_compatible arg order
nikic 261eae0
Add ZEND_COLD'
Girgias 91784e2
Drop TODOs or handle exception
Girgias 4e94989
Typo
Girgias 36ee18e
Add zend_is_op_long_compatible() function instead of repeating the ch…
Girgias c43412e
Revert "Revert test change from 32bit"
Girgias da449b6
Use a lower float value
Girgias 843e7f1
Hopefully fix Win test
Girgias de37806
Move IS_ARRAY check to is_op_long_compatible
Girgias 95eae55
Remove redundant parens
Girgias 8befb02
Remove obsolete TODO comment
Girgias da2d7cf
Cast to string instead of int in mysqli test
Girgias 3fe7801
Amend array tests
Girgias e8c1c45
Revert printf changes (do not warn)
Girgias c536d4d
Fix test
Girgias de5fe1d
Drop TODO comment
Girgias d4e1f8e
Fixup after %0 specifier has been introduced for null bytes in run-test
Girgias 473e14c
Revert changes to formatted_print.c
Girgias 3f030bf
Drop useless test
Girgias ac925c4
Drop printf test changes
Girgias 09a8044
Fix copy/paste mistake from 32bit to 64bit tests in math tests
Girgias File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
Zend/tests/float_to_int/explicit_casts_should_not_warn.phpt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
--TEST-- | ||
Explicit (int) cast must not warn | ||
--SKIPIF-- | ||
<?php | ||
if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only"); | ||
?> | ||
--FILE-- | ||
<?php | ||
|
||
$values =[ | ||
3.0, | ||
3.5, | ||
10e120, | ||
10e300, | ||
fdiv(0, 0), | ||
(string) 3.0, | ||
(string) 3.5, | ||
(string) 10e120, | ||
(string) 10e300, | ||
(string) fdiv(0, 0), | ||
]; | ||
|
||
foreach($values as $value) { | ||
var_dump((int) $value); | ||
} | ||
|
||
?> | ||
--EXPECT-- | ||
int(3) | ||
int(3) | ||
int(0) | ||
int(0) | ||
int(0) | ||
int(3) | ||
int(3) | ||
int(9223372036854775807) | ||
int(9223372036854775807) | ||
int(0) |
38 changes: 38 additions & 0 deletions
38
Zend/tests/float_to_int/explicit_casts_should_not_warn_32bit.phpt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
--TEST-- | ||
Explicit (int) cast must not warn 32bit variation | ||
--SKIPIF-- | ||
<?php | ||
if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only"); | ||
?> | ||
--FILE-- | ||
<?php | ||
|
||
$values =[ | ||
3.0, | ||
3.5, | ||
10e120, | ||
10e300, | ||
fdiv(0, 0), | ||
(string) 3.0, | ||
(string) 3.5, | ||
(string) 10e120, | ||
(string) 10e300, | ||
(string) fdiv(0, 0), | ||
]; | ||
|
||
foreach($values as $value) { | ||
var_dump((int) $value); | ||
} | ||
|
||
?> | ||
--EXPECT-- | ||
int(3) | ||
int(3) | ||
int(0) | ||
int(0) | ||
int(0) | ||
int(3) | ||
int(3) | ||
int(2147483647) | ||
int(2147483647) | ||
int(0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--TEST-- | ||
Negative 0 check | ||
--FILE-- | ||
<?php | ||
|
||
$negativeZero = -0.0; | ||
var_dump($negativeZero); | ||
var_dump($negativeZero === (float)(int)$negativeZero); | ||
var_dump($negativeZero === 0.0); | ||
|
||
?> | ||
--EXPECT-- | ||
float(-0) | ||
bool(true) | ||
bool(true) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.