Rana Ghosh Rana Ghosh - 1 year ago 372
PHP Question

Parse error: Invalid numeric literal

I have the following error while running this code below:


$a = array(00001, 00008, 00009, 00012);


Parse error: Invalid numeric literal.

Why this issue occurred and how do i solve this?

Answer Source

This comes from the changes made to how integers, specifically octals, are handled in PHP7 (as oppsoed to PHP5).

From the documentation (from PHP7 migration)

Invalid octal literals

Previously, octal literals that contained invalid numbers were silently truncated (0128 was taken as 012). Now, an invalid octal literal will cause a parse error.

From the documentation of integers

Prior to PHP 7, if an invalid digit was given in an octal integer (i.e. 8 or 9), the rest of the number was ignored. Since PHP 7, a parse error is emitted.

Either use them as strings, or actual integers

$a = array(1, 8, 9, 12); // Integers
$a = array("00001", "00008", "00009", "00012"); // Strings
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download