Given collection:
$collection = [
new \stdClass(),
new ClassName(),
new class extends ClassName() {},
10,
'10',
'string value',
];
foreach ($collection as ClassName $val) {
}
is equivalent of:
foreach ($collection as $val) {
if ($val instanceof ClassName) {
}
}
foreach ($collection as int $val) {
}
is equivalent of:
foreach ($collection as $val) {
if (is_int($val)) {
}
}
or
foreach ($collection as $val) {
$val = (int)$val;
}
foreach ($collection as int $key => $val) {
}
foreach ($collection as int $key => ClassName $val) {
}
foreach ($collection as ClassName|int $val) {
}
foreach ($collection as array list($a, $v)) {
}
foreach ($collection as $key => void) {
}
foreach ($collection as int $key => void) {
}