-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Permit trailing whitespace in numeric strings
This is part 1 of the 'Saner Numeric Strings' RFC: https://wiki.php.net/rfc/saner-numeric-strings
- Loading branch information
1 parent
99ee73e
commit f759936
Showing
9 changed files
with
93 additions
and
24 deletions.
There are no files selected for viewing
This file contains 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,59 @@ | ||
--TEST-- | ||
Acceptance of whitespace in numeric strings | ||
--FILE-- | ||
<?php | ||
|
||
$strings = [ | ||
"123", | ||
"123 ", | ||
"123 \t\n\r\v\f", | ||
" 123", | ||
" \t\n\r\v\f123", | ||
" 123 ", | ||
" \t\n\r\v\f123 \t\n\r\v\f", | ||
"123.0", | ||
"123.0 ", | ||
"123.0 \t\n\r\v\f", | ||
" 123.0", | ||
" \t\n\r\v\f123.0", | ||
" 123.0 ", | ||
" \t\n\r\v\f123 \t\n\r\v\f", | ||
"123e0", | ||
"123e0 ", | ||
"123e0 \t\n\r\v\f", | ||
" 123e0", | ||
" \t\n\r\v\f123e0", | ||
" 123e0 ", | ||
" \t\n\r\v\f123e0 \t\n\r\v\f" | ||
]; | ||
|
||
function takes_integer(int $i) { | ||
\assert($i === 123); | ||
} | ||
function takes_float(float $f) { | ||
\assert($f === 123.0); | ||
} | ||
|
||
foreach ($strings as $string) { | ||
\assert($string == 123); | ||
$num = +$string; | ||
\assert($num == 123); | ||
takes_integer($string); | ||
takes_float($string); | ||
\assert(\intdiv($string, 1) === 123); | ||
\assert(\is_numeric($string)); | ||
$incremented = $string; | ||
++$incremented; | ||
\assert(\is_int($incremented) || \is_float($incremented)); | ||
\assert($incremented == 124); | ||
$decremented = $string; | ||
--$decremented; | ||
\assert(\is_int($decremented) || \is_float($decremented)); | ||
\assert($decremented == 122); | ||
} | ||
|
||
echo "OK!", PHP_EOL; | ||
|
||
?> | ||
--EXPECT-- | ||
OK! |
This file contains 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 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 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 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 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 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 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 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