gpt4 book ai didi

php常量数学运算

转载 作者:行者123 更新时间:2023-12-02 11:24:34 25 4
gpt4 key购买 nike

目前我正在学习php。我很困惑这是我的 php 代码

class OBJECT_ENUM
{
const USER = 10;
const POST = 30;
const SECURE_REQUEST = 40;
}

class OPERATION_ENUM
{
const INSERT_USER = OBJECT_ENUM::USER + 1; // <- here it gives an error
const SEND_MAIL = OBJECT_ENUM::USER + 2;

const LIKE_POST = OBJECT_ENUM::POST + 1;
const INSERT_POST = OBJECT_ENUM::POST + 2;

const ENCRYPT = OBJECT_ENUM::SECURE_REQUEST + 1;
}

error message:
Parse error: syntax error, unexpected '+', expecting ',' or ';' in /var/www/workspace/6thAssignment/include/tempCall.php on line 15

我只是不明白为什么会发生这个错误。?有人能给我解释一下吗??

提前谢谢

最佳答案

原始答案:

正如您在 http://www.php.net/manual/en/language.oop5.constants.php 中看到的那样:

The value must be a constant expression, not (for example) a variable, a property, a result of a mathematical operation, or a function call.

更新:

从 PHP 版本 5.6 now it is possible to use expressions为常数。

关于php常量数学运算,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19510501/

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