Skip to content
PHP Logo

In what scenarios does PHP treat numeric literals as octal numbers, and how can developers prevent this from causing errors in their code?

PHP treats numeric literals as octal numbers when they are prefixed with a 0 (zero). This can lead to unexpected results or errors in calculations if developers are not aware of this behavior. To prevent this from causing issues in your code, always ensure that numeric literals are not prefixed with a 0 when working with decimal numbers.

php
// Incorrect usage of octal number
$number = 0755; // This will be treated as octal 755

// Correct way to specify decimal number
$number = 755; // This is a decimal number