致命错误:无法声明类 ProductFilterIterator,因为该名称已在
Posted
技术标签:
【中文标题】致命错误:无法声明类 ProductFilterIterator,因为该名称已在【英文标题】:Fatal error: Cannot declare class ProductFilterIterator, because the name is already in use in 【发布时间】:2020-03-20 04:29:06 【问题描述】:借助 ProductFilterIterator 类想要获取数据
class ProductFilterIterator extends \FilterIterator
protected $filter;
protected $length;
public function __construct(\Iterator $iterator, $filter)
$this->filter = $filter;
$this->length = -strlen($filter);
parent::__construct($iterator);
public function accept() : bool
$current = $this->getInnerIterator()->current();
return substr($current['Товар'], $this->length) == $this->filter;
$iterator = (new \ArrayObject($obj['items']))->getIterator();
$filter = new ProductFilterIterator($iterator, $arPart['ARTICLE']);
foreach ($filter as $obj)
echo "<pre>";
我收到一个错误 - 使用中
【问题讨论】:
你能指定你正在使用的框架吗? 你看过之前的教程了吗? blog.floriancourgey.com/2018/05/… 因此,如果您在没有 Prestashop 的情况下工作,您需要将 Smarty 集成到您的系统中。 包括依赖packagist.org/packages/smarty/smarty和设置smarty.net/docs/en/installing.smarty.basic.tpl 这很难解释... 【参考方案1】:尝试使用命名空间,
namespace Custom;
class ProductFilterIterator extends \FilterIterator
protected $filter;
protected $length;
public function __construct(\Iterator $iterator, $filter)
$this->filter = $filter;
$this->length = -\strlen($filter);
parent::__construct($iterator);
public function accept() : bool
$current = $this->getInnerIterator()->current();
return \substr($current['Товар'], $this->length) == $this->filter;
$iterator = (new \ArrayObject($obj['items']))->getIterator();
$filter = new ProductFilterIterator($iterator, $arPart['ARTICLE']);
foreach ($filter as $obj)
echo "<pre>";
【讨论】:
以上是关于致命错误:无法声明类 ProductFilterIterator,因为该名称已在的主要内容,如果未能解决你的问题,请参考以下文章
致命错误:无法声明类 ProductFilterIterator,因为该名称已在