rfc:explicit_octal_notation

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
rfc:explicit_octal_notation [2020/10/20 23:46] crellrfc:explicit_octal_notation [2020/11/07 08:33] – Add explicit mention of upper case notation. girgias
Line 3: Line 3:
   * Date: 2020-10-20   * Date: 2020-10-20
   * Author: George Peter Banyard, <girgias@php.net>   * Author: George Peter Banyard, <girgias@php.net>
-  * Status: Draft+  * Status: Under Discussion
   * First Published at: https://wiki.php.net/rfc/explicit_octal_notation   * First Published at: https://wiki.php.net/rfc/explicit_octal_notation
  
Line 11: Line 11:
  
 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 [[https://docs.python.org/3/reference/lexical_analysis.html#integer-literals|[1]]][[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Numbers_and_dates|[2]]][[https://doc.rust-lang.org/rust-by-example/primitives/literals.html|[3]]] only accept or support an explicit octal notation ''0o''. 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 [[https://docs.python.org/3/reference/lexical_analysis.html#integer-literals|[1]]][[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Numbers_and_dates|[2]]][[https://doc.rust-lang.org/rust-by-example/primitives/literals.html|[3]]] only accept or support an explicit octal notation ''0o''.
 +
 +Surprisingly PHP already has support for this notation when using the <php>octdec()</php> and <php>base_convert()</php> functions.
  
 ===== Proposal ===== ===== Proposal =====
  
-Add support for the explicit octal notation ''0o'' for integer literals analogous to ''0x'' and ''0b'' for hexadecimal and binary.+Add support for the explicit octal notation ''0o''/''0O'' for integer literals analogous to ''0x''/''0X'' and ''0b''/''0B'' for hexadecimal and binary.
  
 <code php> <code php>
 0o16 === 14; // true 0o16 === 14; // true
 0o123 === 83; // true 0o123 === 83; // true
 +
 +0O16 === 14; // true
 +0O123 === 83; // true
  
 016 === 0o16; // true 016 === 0o16; // true
 +016 === 0O16; // true
 </code> </code>
  
Line 40: Line 46:
 ==== To Existing Extensions ==== ==== To Existing Extensions ====
 Added support to the GMP extension. Added support to the GMP extension.
 +
 +Added support to the <php>FILTER_VALIDATE_INT</php> filter when using the <php>FILTER_FLAG_ALLOW_OCTAL</php> flag
  
 ==== To Opcache ==== ==== To Opcache ====
Line 81: Line 89:
 [[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Numbers_and_dates|[2]]] JavaScript language references about numbers \\ [[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Numbers_and_dates|[2]]] JavaScript language references about numbers \\
 [[https://doc.rust-lang.org/rust-by-example/primitives/literals.html|[3]]] Rust language reference about literals \\ [[https://doc.rust-lang.org/rust-by-example/primitives/literals.html|[3]]] Rust language reference about literals \\
-[[rfc:remove_hex_support_in_numeric_strings|4]] PHP RFC: Remove hex support in numeric strings+[[rfc:remove_hex_support_in_numeric_strings|[4]]] PHP RFC: Remove hex support in numeric strings
  
  
rfc/explicit_octal_notation.txt · Last modified: 2021/01/04 20:12 by girgias