本文介绍了解析错误:无效的数字文字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在下面运行此代码时出现以下错误:
I have the following error while running this code below:
代码:
<?php
$a = array(00001, 00008, 00009, 00012);
print_r($a);
?>
错误:
为什么会出现此问题,我该如何解决?
Why this issue occurred and how do i solve this?
推荐答案
这来自对PHP7中整数(尤其是八进制)的处理方式所做的更改(与PHP5相对).
This comes from the changes made to how integers, specifically octals, are handled in PHP7 (as oppsoed to PHP5).
来自文档(来自PHP7迁移)
From the documentation (from PHP7 migration)
以前,包含无效数字的八进制文字被无声地截断(0128被视为012).现在,无效的八进制文字将导致解析错误.
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.
摘自整数文档
将它们用作字符串或实际整数
Either use them as strings, or actual integers
$a = array(1, 8, 9, 12); // Integers
$a = array("00001", "00008", "00009", "00012"); // Strings
- PHP7与PHP5的示例: https://3v4l.org/GRZF2
- http://php.net/manual/en/language.types. integer.php
- 手册: http://php. net/manual/en/migration70.incompatible.php
- Example of PHP7 vs PHP5: https://3v4l.org/GRZF2
- http://php.net/manual/en/language.types.integer.php
- Manual: http://php.net/manual/en/migration70.incompatible.php
这篇关于解析错误:无效的数字文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!