ID: 45747
Updated by: [EMAIL PROTECTED]
Reported By: info at netmosfera dot it
-Status: Open
+Status: Bogus
Bug Type: Feature/Change Request
Operating System: Irrelevant
PHP Version: 5.3.0alpha1
New Comment:
Have a look at the ITerator and IteratorAggregate interfaces for
implementing inner and outer iterators in PHP.
Previous Comments:
------------------------------------------------------------------------
[2008-08-07 22:51:21] info at netmosfera dot it
Description:
------------
Hello, im asking for a magic method in oop
__iteration()
that is how i want it work
a special __get, but for the iteration (foreach)
please just read the code :D
thank you
Reproduce code:
---------------
<?php
class Test
{
private $pointer = -1;
private $fields = array();
private $values = array();
public function __set($name, $value)
{
$this->fields[] = $name;
$this->values[] = $value;
}
public function __get($name)
{
list($key) = array_keys($this->fields, $name);
return $this->values[$key];
}
public function __iteration($name, $value)
{
/*
my
useful [...]
code
*/
$this->pointer++;
return array($this->fields[$this->pointer],
$this->values[$this->pointer]);
}
}
$php = new Test();
$php->just = "a";
$php->a = "b";
$php->simple = "c";
$php->test = "d";
foreach($php as $field => $value)
{
echo $field . "=" . $value . "<br>";
}
?>
Expected result:
----------------
just = a
a = b
simple = c
test = d
Actual result:
--------------
no result
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=45747&edit=1