How to Represent Octal Literals in PHP?

Explicit octal numeral notation in PHP

In PHP, an octal literal can be specified in any of the following ways:

  • Prefixing the number with 0;
  • (PHP 8.1+) Prefixing the number with 0o (or 0O).

For example, the following are all valid octal literal numbers:

echo 030071; // 12345
echo 0o30071; // 12345 (PHP 8.1+)
echo 0O30071; // 12345 (PHP 8.1+)

All the different octal notations are equivalent:

var_dump(030071 === 12345); // true
var_dump(030071 === 0o30071); // true
var_dump(0o30071 === 0O30071); // true

Hope you found this post useful. It was published . Please show your love and support by sharing this post.