[英]Fatal error: Cannot declare class ProductFilterIterator, because the name is already in use in
With the help of class ProductFilterIterator want to get data借助 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>";
I'm getting an error- Fatal error: Cannot declare class ProductFilterIterator, because the name is already in use in我收到一个错误 - 致命错误:无法声明类 ProductFilterIterator,因为该名称已在
Try using Namespace,尝试使用命名空间,
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>";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.