Skip to content

Fix Traversable description - #5773

Merged
lacatoire merged 2 commits into
php:masterfrom
mmalferov:patch-4
Aug 19, 2026
Merged

Fix Traversable description#5773
lacatoire merged 2 commits into
php:masterfrom
mmalferov:patch-4

Conversation

@mmalferov

@mmalferov mmalferov commented Aug 18, 2026

Copy link
Copy Markdown
Member

Following by:

https://bugs.php.net/bug.php?id=62609

and

php/php-src@e9ae581

It seems the implements Traversable construct for abstract classes was introduced only as of PHP 8.0.0, not in 7.4.0.

The following example works only as of PHP 8.0.0. Prior to 8.0.0, including [7.4.0, 7.4.33], it generates:

Fatal error: Class AbstractTraversable must implement interface Traversable as part of either Iterator or IteratorAggregate:

<?php

abstract class AbstractTraversable implements Traversable {}

class NonAbstractTraversable extends AbstractTraversable implements IteratorAggregate
{
    public function getIterator()
    {
        yield from ['foo', 'bar',];
    }
}

foreach (new NonAbstractTraversable() as $value) {
    echo $value, "\n";
}

@lacatoire
lacatoire merged commit 14013fe into php:master Aug 19, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants