[php-src] Issue #8156: Classes extending `SplFixedArray` can not implement `RecursiveIterator`
| From: | ghostwriter | Date: | Mon, 28 Feb 2022 00:31:03 +0000 |
| Subject: | [php-src] Issue #8156: Classes extending `SplFixedArray` can not implement `RecursiveIterator` | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-240064@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/8156
Author: ghostwriter
### Description
The following code:
---
```php
<?php
class RecursiveFixedArray extends SplFixedArray implements RecursiveIterator
{
public function getChildren(): ?RecursiveIterator
{
return $this->current();
}
public function hasChildren(): bool
{
return $this->current() instanceof RecursiveFixedArray;
}
}
```
Resulted in this output:
---
> Fatal error: Class
RecursiveFixedArray cannot implement both
> Iterator and IteratorAggregate at
> the same time
But I expected this output instead:
---
```
// No error
```
Goal:
---
To recursively iterate over a SplFixedArray, to save memory and improve performance.
Is this intended, a bug? https://3v4l.org/ufapQ
* SplFixedArray (extends IteratorAggregate )
* RecursiveIterator (extends Iterator).
### PHP Version
8.0.1 - 8.0.16, 8.1.0 - 8.1.3
### Operating System
_No response_