gpt4 book ai didi

php - 解析错误 : Invalid numeric literal

转载 作者:IT王子 更新时间:2023-10-28 23:53:11 24 4
gpt4 key购买 nike

运行下面这段代码时出现以下错误:

代码:

<?php
$a = array(00001, 00008, 00009, 00012);
print_r($a);
?>

错误:

Parse error: Invalid numeric literal.

为什么会出现这个问题,我该如何解决?

最佳答案

这是因为在 PHP7 中处理整数(特别是八进制)的方式发生了变化(与 PHP5 不同)。

来自文档(来自 PHP7 迁移)

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.

来自整数的文档

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.

将它们用作字符串或实际整数

$a = array(1, 8, 9, 12); // Integers
$a = array("00001", "00008", "00009", "00012"); // Strings

关于php - 解析错误 : Invalid numeric literal,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40735963/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com