ID: 28444
Comment by: php at rodric dot org
Reported By: dennis at inmarket dot lviv dot ua
Status: Assigned
Bug Type: Class/Object related
Operating System: WinXP
PHP Version: 5.0.0RC2
Assigned To: andi
New Comment:
I ran into this in a slightly different way -- trying to
foreach through an ArrayAccess object. Interestingly,
removing the __set from class O allows this to work.
class O
{
private $m_a = array();
function __get ($key)
{
return $this->m_a[$key];
}
function __set ($key, $val)
{
$this->m_a[$key] = $val;
}
}
class A implements ArrayAccess, IteratorAggregate
{
private $m_e = array();
function __construct ($e = NULL)
{
$this->m_e = is_null ($e) ? array() : $e;
}
function offsetSet ($key, $value)
{
$this->m_e[$key] = $value;
}
function offsetGet ($key)
{
if (isset ($this->m_e[$key]))
{
return $this->m_e[$key];
}
}
function offsetUnset ($key)
{
unset ($this->m_e[$key]);
}
function offsetExists ($key)
{
return isset ($this->m_e[$key]);
}
function getIterator ()
{
return new ArrayIterator($this->m_e);
}
}
$o = new O();
$o->a = new A(array(1, 2, 3));
foreach ($o->a as $e)
{
echo "$e ";
}
Previous Comments:
------------------------------------------------------------------------
[2004-10-13 14:05:03] info at pandora-web dot de
Another Test Case:
---------------
class TestClass {
private $_p = array();
public function __get($propName){
return $this->_p[$propName];
}
public function __set($propName, $propValue){
$this->_p[$propName] = $value;
}
}
$a = new TestClass();
$a->testVar = 'test';
print $a->testVar; //--> 'test'
$a->testVar = new TestClass();
$a->testVar->testVar = 'test2';
// __set of $a->testVar called instead
of getter of $a->testVar and setter of $a->testVar->testVar
Solution Hint:
----------------
I think I is better to call the __get method of the first objects and
than call the __set method of the last one in chain. Like you with
__call.
------------------------------------------------------------------------
[2004-08-21 03:21:10] matth at alsync dot com
Another work around for this is:
a->b->__set('c', 'value');
At least the underlying calsses do not need to be changed to make this
work.
------------------------------------------------------------------------
[2004-08-05 11:19:49] dennis at inmarket dot lviv dot ua
To [EMAIL PROTECTED]: Please don't feel hurt by this comment. I think you
guys did a great job on making PHP5 what it is, but this bug is
different. I think (but I mon sure, since I don't get anything in the
PHP engine code) this should fix very well.
------------------------------------------------------------------------
[2004-08-05 11:04:45] [EMAIL PROTECTED]
There are plenty of other non fixed bugs. If we were to release when
the bug count reaches zero we would never release.
------------------------------------------------------------------------
[2004-08-05 10:52:50] dennis at inmarket dot lviv dot ua
In my opinion, such "workarounds" should be replaced by fixing the
issue in PHP itself. Indeed, it is funny that this works for getting
properties, and doesn't for setting. Onother question: how did PHP5
make for a release with this core level bug?
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/28444
--
Edit this bug report at http://bugs.php.net/?id=28444&edit=1