Skip to content

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

Development

Successfully merging this pull request may close these issues.

2 participants