PHP 错误 : Unparenthesized `a ? b : c ? d : e` is deprecated. 使用 `(a ? b : c) ? d : e` 或 `a ? b : (c ? d : e)`

标签 php foreach reference deprecated isset

这个问题在这里已经有了答案:





Stacking Multiple Ternary Operators in PHP

(10 个回答)



How to avoid undefined index warning for chains of 'default' values?

(3 个回答)


10 个月前关闭。




我正在使用 用于 Laravel 应用程序的 PHP 7.4 我经常收到这个异常。

ErrorException (E_DEPRECATED)
Unparenthesized `a ? b : c ? d : e` is deprecated. Use either `(a ? b : c) ? d : e` or `a ? b : (c ? d : e)`
触发此异常的代码是:
foreach ($allLanguages as $languageKey) {
    $original[$languageKey] =
        isset($values[$languageKey])
            ? $values[$languageKey]
            : isset($filesContent[$fileName][$languageKey][$key]) ? $filesContent[$fileName][$languageKey][$key] : '';
}
任何人都可以帮助我解决这个问题吗?
发现这是由于 PHP 升级导致的 E_DEPRECATED 错误,但有什么方法可以解决 通过将弃用的代码转换为最新的 来解决此异常?

最佳答案

在你的情况下,你应该使用 ?? instead of isset and ternaries :

foreach ($allLanguages as $languageKey) {
    $original[$languageKey] = $values[$languageKey]??  $filesContent[$fileName][$languageKey][$key] ?? '';
}

关于PHP 错误 : Unparenthesized `a ? b : c ? d : e` is deprecated. 使用 `(a ? b : c) ? d : e` 或 `a ? b : (c ? d : e)`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61432488/

相关文章:

Java 引用传递不起作用?

java - 在子方法中创建新对象显然不会传递引用

PHP 攻击服务器,这段代码在做什么?

php - Joomla PHP MySQL 查询使用 MySQL IF 函数

c++ - 在对象 vector 上调用成员函数

php - foreach 循环重复数组中的最后一项

sql-server - SSIS并行处理foreach循环

linux - 什么是 Linux 上的 Rootkit Dragon Book?

php - 只允许 friend 在他们的个人资料页面发表评论

php - Smarty {if $foo} 相当于 isset()