gpt4 book ai didi

php - 为什么这个php数组函数给我一个错误

转载 作者:行者123 更新时间:2023-12-03 08:32:58 24 4
gpt4 key购买 nike

if (array_key_exists('icon_path', $changedAttributes)) {
$iconFile = $changedAttributes["icon_path"];
}
为什么 $iconFile = $changedAttributes["icon_path"];行在 php 7.2 中给我以下错误?
即使我将其更改为单引号, ['icon_path']也无法解决问题。
syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting '-' or identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING)
但是在 php 7.4 中,完全没有问题。
我使用此版本检查器检查了我的代码
https://www.piliapp.com/php-syntax-check/
7.2给了我这个错误,但是7.4可以正常工作。

最佳答案

这是一个缩进问题。我的代码包含以下JavaScript代码。

public function reloadPageOnEdit()
{
return <<<JSCRIPT
<script>
function openWindowReload(link) {
var href = link.href;

document.location.reload(true);
window.open(href,'_self');
}
</script>
JSCRIPT;
}
我把它缩进了最左边。它解决了问题。即使在7.4中,也没有问题,而7.2。
我很困惑,因为代码在其他地方失败了。
    public function reloadPageOnEdit()
{
return <<<JSCRIPT
<script>
function openWindowReload(link) {
var href = link.href;

document.location.reload(true);
window.open(href,'_self');
}
</script>
JSCRIPT;
}

关于php - 为什么这个php数组函数给我一个错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65197717/

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