1.2.103. Can’t Implement Traversable¶
It is not possible to implement the Traversable
interface directly. It is possible to implement it via the Iterator
and IteratorAggregate
classes, which, in turn, implements Traversable
.
Traversable
may be useful when used with instanceof
, catch
or any type specification.
<?php
// This lints, but doesn't run
class x implements Traversable {
}
if( $argument instanceof Traversable ) {
// doSomething
}
?>
See also Traversable, Iterator and IteratorAggregate.
1.2.103.2. Connex PHP features¶
1.2.103.2.1. Suggestions¶
Extend
Iterator
orIteratorAggregate
.
1.2.103.2.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 |
Note |
This issue may lint but will not run |
Available in |