Tienes razon, muchas gracias por resolver mi duda, como para cerrar y completar lo dicho (que esta muy claro) hice este codigo:
Código PHP:
Ver original<?php
class A implements Iterator
{
public $datos = [1, 2, 3, 4, 5];
public function key() { return key($this->datos); } public function next() { return next($this->datos); } public function valid
() { return (key($this->datos) !== NULL && key($this->datos) !== FALSE); } public function __destruct()
{
echo("destruido");
}
}
$test = new A();
$instancia = $test;
foreach($instancia as $test)
{
}
cuya salida es:
Cita: object(A)#1 (1) refcount(3){ ["datos"]=> array(5) refcount(1){ [0]=> long(1) refcount(2) [1]=> long(2) refcount(2) [2]=> long(3) refcount(2) [3]=> long(4) refcount(2) [4]=> long(5) refcount(2) } } object(A)#1 (1) refcount(3){ ["datos"]=> array(5) refcount(1){ [0]=> long(1) refcount(2) [1]=> long(2) refcount(2) [2]=> long(3) refcount(2) [3]=> long(4) refcount(2) [4]=> long(5) refcount(2) } }
int 1
object(A)#1 (1) refcount(3){ ["datos"]=> array(5) refcount(1){ [0]=> long(1) refcount(2) [1]=> long(2) refcount(2) [2]=> long(3) refcount(2) [3]=> long(4) refcount(2) [4]=> long(5) refcount(2) } }
int 2
object(A)#1 (1) refcount(3){ ["datos"]=> array(5) refcount(1){ [0]=> long(1) refcount(2) [1]=> long(2) refcount(2) [2]=> long(3) refcount(2) [3]=> long(4) refcount(2) [4]=> long(5) refcount(2) } }
int 3
object(A)#1 (1) refcount(3){ ["datos"]=> array(5) refcount(1){ [0]=> long(1) refcount(2) [1]=> long(2) refcount(2) [2]=> long(3) refcount(2) [3]=> long(4) refcount(2) [4]=> long(5) refcount(2) } }
int 4
object(A)#1 (1) refcount(3){ ["datos"]=> array(5) refcount(1){ [0]=> long(1) refcount(2) [1]=> long(2) refcount(2) [2]=> long(3) refcount(2) [3]=> long(4) refcount(2) [4]=> long(5) refcount(2) } }
int 5
int 5
destruido
alli se ve que la cantidad de referencias al objeto aumenta dentro del foreach (sigue igual, pero porque una se elimina al hacer la asignacion) confirmándose lo que dices.
Saludos.