This is an old revision of the document!
PHP RFC: Explicit octal integer literal notation
- Version: 0.9
- Date: 2020-10-20
- Author: George Peter Banyard, girgias@php.net
- Status: Draft
- First Published at: https://wiki.php.net/rfc/explicit_octal_notation
Introduction
PHP's literal octal notation can lead to some confusing results such as "016" == 016
evaluating to false. This is because “016” is evaluated as an octal integer and resolves to 14
.
This convention for octal integers is well established and followed by many programming languages (Java, C, C#, Golang, Haskell, and more). However, Python, JavaScript, and Rust [1][2][3] only accept or support an explicit octal notation 0o
.
Proposal
Add support for the explicit octal notation 0o
for integer literals analogous to 0x
and 0b
for hexadecimal and binary.
Backward Incompatible Changes
None
Proposed PHP Version(s)
Next PHP 8.x.
RFC Impact
To Existing Extensions
Added support to the GMP extension.
To Opcache
None
Unaffected PHP Functionality
Implicit octal notation is unaffected.
Future Scope
- Deprecate the implicit octal notation.
Proposed Voting Choices
Include these so readers know where you are heading and can discuss the proposed voting options.
Patches and Tests
GitHub patch: https://github.com/php/php-src/pull/6360
Language specification patch TBD.
Implementation
After the project is implemented, this section should contain
- the version(s) it was merged into
- a link to the git commit(s)
- a link to the PHP manual entry for the feature
- a link to the language specification section (if any)