Closed
Conversation
e923320 to
b9f9eea
Compare
nikic
reviewed
Oct 26, 2020
b9f9eea to
28d7486
Compare
28d7486 to
bf13d7c
Compare
TysonAndre
reviewed
Nov 13, 2020
nikic
reviewed
Nov 25, 2020
Zend/zend_language_scanner.l
Outdated
| /* zend_oct_strtod skips leading '0' */ | ||
| ZVAL_DOUBLE(zendlval, zend_oct_strtod(octal, (const char **)&end)); | ||
| ZEND_ASSERT(!errno); | ||
| /* errno isn't checked since we allow HUGE_VAL/INF overflow */ |
Member
There was a problem hiding this comment.
Mismatch between this comment and the preceding assert. Can you please add a test for a very large octal literal that overflows to INF?
Member
Author
There was a problem hiding this comment.
Will do, I'm adding a bunch of tests for the other integer literals while I'm at it.
61b83ec to
4e68814
Compare
0b6a8a3 to
7a32bf1
Compare
7a32bf1 to
cae80af
Compare
nikic
approved these changes
Jan 4, 2021
Member
nikic
left a comment
There was a problem hiding this comment.
Looks fine assuming CI is happy...
| strip_underscores(octal, &len); | ||
| } | ||
|
|
||
| /* Reset errno */ |
| echo 'Octal to decimal:', \PHP_EOL; | ||
| var_dump(base_convert('0o', 8, 10)); | ||
| var_dump(base_convert('0O', 8, 10)); | ||
| var_dump(base_convert('0', 8, 10)); // This is somehow deprecated???? |
Member
Author
There was a problem hiding this comment.
Ah right, that was when I messed up by confusing 0 and O ... will drop it
jrfnl
added a commit
to PHPCSStandards/PHPCSUtils
that referenced
this pull request
Feb 28, 2022
This add support for the explicit octal notation using a `0o`/`0O` prefix as supported in PHP as of PHP 8.1. The only method which needed adjusting was the `Numbers::getCompleteNumber()` method, which now backfills the tokenization when needed. For the `Numbers::isOctalInt()` method, a small tweak to the regex was all that was needed. As for the `Numbers::getDecimalValue()` method: this already handled the conversion correctly due to the use of the PHP native `octdec()` function. From the RFC: > Surprisingly PHP already has support for this notation when using the `octdec()` and `base_convert()` functions. Includes adding unit tests to safeguard support in all relevant methods in the class. Refs: * https://wiki.php.net/rfc/explicit_octal_notation * php/php-src#6360 * squizlabs/PHP_CodeSniffer#3481 * squizlabs/PHP_CodeSniffer#3552
jrfnl
added a commit
to PHPCompatibility/PHPCompatibility
that referenced
this pull request
Dec 5, 2022
…niff > **Integer Octal Literal Prefix** > > Octal integers can now use an explicit `0o`/`0O` prefix in integer literals, similarly to binary and hexadecimal integer literals. Includes unit tests. Includes documentation. Refs: * https://www.php.net/manual/en/migration81.new-features.php#migration81.new-features.core.octal-literal-prefix * https://wiki.php.net/rfc/explicit_octal_notation * php/php-src#6360 * php/php-src@589bdf3
jrfnl
added a commit
to PHPCompatibility/PHPCompatibility
that referenced
this pull request
Dec 5, 2022
…niff > **Integer Octal Literal Prefix** > > Octal integers can now use an explicit `0o`/`0O` prefix in integer literals, similarly to binary and hexadecimal integer literals. Includes unit tests. Includes documentation. Refs: * https://www.php.net/manual/en/migration81.new-features.php#migration81.new-features.core.octal-literal-prefix * https://wiki.php.net/rfc/explicit_octal_notation * php/php-src#6360 * php/php-src@589bdf3
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
RFC still needs to be written butthe primary motivation is that"016" == 016is equal to false as016is interpreted as an octal integer and can be surprising.RFC: https://wiki.php.net/rfc/explicit_octal_notation
Albeit PHP's way of dealing with octal is well established (C, Java, Golang, Haskell, etc.) other languages provide the
0oprefix for octal integer analogous to0band0xfor binary and hexadecimal integers.TODO: Add support for:
filter_var('0o77', FILTER_VALIDATE_INT, FILTER_FLAG_ALLOW_OCTAL)octdec('0o77')(Actually PHP already supports this)References: