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 revisionBoth sides next revision
rfc:explicit_octal_notation [2020/11/07 08:33] – Add explicit mention of upper case notation. girgiasrfc:explicit_octal_notation [2020/11/07 08:50] – Flesh out section about numeric strings. girgias
Line 8: Line 8:
 ===== Introduction ===== ===== Introduction =====
  
-PHP's literal octal notation can lead to some confusing results such as <php>"016" == 016</php> evaluating to false. This is because ''016'' is evaluated as an octal integer and resolves to ''14''.+PHP's literal octal notation can lead to some confusing results such as <php>16 === 016</php> 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 [[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''.
Line 35: Line 35:
 <blockquote>supporting octal numbers is not possible, because handling the string '0123' as the number 83 would be highly unexpected for end users of an application.</blockquote> <blockquote>supporting octal numbers is not possible, because handling the string '0123' as the number 83 would be highly unexpected for end users of an application.</blockquote>
  
-Therefore, this RFC has no impact on numeric strings.  ''"0o16"'' is still interpreted as a string and only a string.+Numeric strings in PHP are //always// decimal. Analogous to the example from the introduction <php>"016" == 016</php> evaluates to false as <php>(int) "016"</php> evaluates to ''16''
 + 
 +This RFC has no impact on the behaviour of numeric strings.  ''"0o16"'' would still be interpreted as a string and only a string. Moreover, <php>(int) "0o16"</php> will continue to evaluate to ''0''.
  
 ===== Backward Incompatible Changes ===== ===== Backward Incompatible Changes =====
rfc/explicit_octal_notation.txt · Last modified: 2021/01/04 20:12 by girgias