1.2.1637. foreach() On Object

This analysis reports usage of a foreach() structure on an object. That object shall not be an array, nor an object with array syntax, such as Traversable.

<?php

$a = new Stdclass();
$a->p = 1;
$a->q = 2;

foreach($object as $property => $value) {
    print $property . ' => '. $value.PHP_EOL;
}

?>

1.2.1637.1. Specs

Short name

Structures/ForeachOnObject

Rulesets

All, Analyze

Exakat since

2.6.8

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

High

Available in

Entreprise Edition, Exakat Cloud