gpt4 book ai didi

php - 了解 fatal error : Cannot use temporary expression in write context

转载 作者:可可西里 更新时间:2023-11-01 13:44:38 26 4
gpt4 key购买 nike

我想了解此错误在 PHP 中的确切含义:如何故意创建错误以及如何避免或修复错误。在我下面的简单示例中,我遇到了这个错误:

Fatal error: Cannot use temporary expression in write context in line 11

第 11 行是以下行:

response['error'] = "Error: B is less that C <br />";

错误代码如下:

$response = [];
$a = 4;
$b = 8;
$c = 9;
$d = 29;

if($a !== $b){
$response['error'] = "Error: A is not equal to B <br />";
}elseif($b < $c){
response['error'] = "Error: B is less that C <br />";
}
if($d > $c){
response['success'] = "Success: D is greater than C<br />";
}

echo $response['error'];
echo $response['success'];

我的期望是:

确保正确处理此异常

我知道变量已定义,否则错误将是:

Notice: Undefined variable

最佳答案

您忘记在单词 response 之前包含 $

这在第 11 行和第 14 行中很明显,如下所示:

response['error'] = "Error: B is less that C <br />";

你应该把它改成:

$response['error'] = "Error: B is less that C <br />";

希望这对您有所帮助。

关于php - 了解 fatal error : Cannot use temporary expression in write context,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50853265/

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