Skip to content
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

PHP 8.1 | Numbers: add support for explicit octal notation #293

Merged

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented 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:

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
Copy link
Member Author

jrfnl commented Feb 28, 2022

This PR depends on the upstream PR squizlabs/PHP_CodeSniffer#3552, which needs to be merged first.

@jrfnl jrfnl marked this pull request as ready for review March 18, 2022 09:16
@jrfnl
Copy link
Member Author

jrfnl commented Mar 18, 2022

The upstream PR has been merged 🎉

@jrfnl jrfnl merged commit a6fb661 into develop Mar 18, 2022
@jrfnl jrfnl deleted the php-8.1/numbers-add-support-for-explicit-octal-notation branch March 18, 2022 09:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant