Prestashop错误:试图访问布尔类型值的数组偏移量



我在Prestashop模块中开发了一个自定义页面
我使用的是Prestashop 1.7.7.2和PHP 7.4。
这是控制器代码:

class MymoduleConfirmemailModuleFrontController extends ModuleFrontController
{
public $php_self = 'confirmemail';
public function init()
{
parent::init();
}
public function initContent()
{
parent::initContent();
$this->setTemplate('confirmemail');
}

这是模板文件的代码:

{extends file='page.tpl'}
{block name='page_header_container'}{/block}
{block name='page_content'}
<div>TEST</div>
{/block}

当我导航到相应的页面时,我收到以下错误:
注意:试图访问bool 类型的值的数组偏移量

并且该页面不显示。如果我去掉线CCD_ 1;TEST">

在堆栈跟踪之后,经过一些调试,我发现问题出现在classes/Connection.hp:内的这些行中

[...]
$sql = 'SELECT SQL_NO_CACHE `id_guest`
FROM `' . _DB_PREFIX_ . 'connections`
WHERE `id_guest` = ' . (int) $cookie->id_guest . '
AND `date_add` > '' . pSQL(date('Y-m-d H:i:00', time() - 1800)) . ''
' . Shop::addSqlRestriction(Shop::SHARE_CUSTOMER) . '
ORDER BY `date_add` DESC';
$result = Db::getInstance()->getRow($sql, false);

---> if (!$result['id_guest'] && (int) $cookie->id_guest) {
[...]

问题是查询返回false,因为没有包含id为$cookie->id_guest的id_guest的行,所以最后一行抛出错误。我错过了什么?

您错过了PS 1.7.7.2还不兼容PHP 7.4:

参见

https://devdocs.prestashop.com/1.7/basics/installation/system-requirements/

降级到7.3应该可以解决这个问题。

我通过测试方法getCoverWs是否返回任何结果集以及是否返回false来解决这个问题。我的代码是在classes/Product.php 上更改为以下内容

public function getCoverWs()
{
$result = $this->getCover($this->id);
if (!$result) {
return false;
}
return $result['id_image'];
}
$result = $this->getCover($this->id);
//return $result['id_image'];
if(is_array($result)){
if (array_key_exists('id_image', $result)) {
return $result['id_image'];
}
}
return "";

最新更新