1.2.100. Can’t Implement Traversable

It is not possible to implement the Traversable interface. The alternative is to implement Iterator or IteratorAggregate, which also implements Traversable.

Traversable may be useful when used with instanceof.

<?php

// This lints, but doesn't run
class x implements Traversable {

}

if( $argument instanceof Traversable ) {
    // doSomething
}

?>

See also Traversable, Iterator and IteratorAggregate.

1.2.100.1. Suggestions

  • Implement Iterator or IteratorAggregate

1.2.100.2. Specs

Short name

Interfaces/CantImplementTraversable

Rulesets

All, Analyze, CE, CI-checks, Changed Behavior, LintButWontExec

Exakat since

1.9.8

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

Very high

Features

interface

Note

This issue may lint but will not run

Available in

Entreprise Edition, Community Edition, Exakat Cloud