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
(or0O
).
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
This post was published by Daniyal Hamid. Daniyal currently works as the Head of Engineering in Germany and has 20+ years of experience in software engineering, design and marketing. Please show your love and support by sharing this post.