Issues

ZF-1898: Zend_Db_Table_Row_Abstract::toArray returns a reference to data instead of an array of data

Issue Type: Bug Created: 2007-08-31T14:22:37.000+0000 Last Updated: 2008-09-02T10:39:40.000+0000 Status: Resolved Fix version(s): - 1.6.0 (02/Sep/08)

Reporter: Ralph Schindler (ralph) Assignee: julien PAULI (doctorrock83) Tags: - Zend_Db_Table

Related issues: Attachments:

Description

Bill, I am noticing circular references when I try to return an array:

Ponder this:

<pre class="highlight">
$thing = new ArrayObject($row->toArray(), ArrayObject::ARRAY_AS_PROPS);
$thing->foo= 'bar';

Also adds foo = bar into the _data of the $row.

Perhaps toArray() shoudl cast _data to (Array) before returning it?

-ralph

Comments

Posted by julien PAULI (doctorrock83) on 2007-09-19T05:42:10.000+0000

Yes, ArrayObject's constructor make a reference on the variable passed to it. Casting to array before returning, explicitly tells PHP to make a real copy (not a COW) of the returned array.

See the first comment at http://php.net/manual/en/…

I don't know if this sould be considered as a ZF issue, or a PHP issue, it's actually confused, as you can read in that bug report : http://bugs.php.net/bug.php?id=42065

Posted by Darby Felton (darby) on 2007-09-19T14:01:10.000+0000

I agree that toArray() should return a copy, rather than a reference to the object's properties. A change to a member of the returned value of toArray() that results in changes to the object data seems like unintended behavior.

Since this would be a slight BC break, however, and because I would like to hear Bill's comments on the issue, I remove 1.0.2 from fix version list.

Posted by Wil Sinclair (wil) on 2008-03-25T20:44:00.000+0000

Please categorize/fix as needed.

Posted by Wil Sinclair (wil) on 2008-04-18T13:12:01.000+0000

This doesn't appear to have been fixed in 1.5.0. Please update if this is not correct.

Posted by julien PAULI (doctorrock83) on 2008-04-24T17:31:11.000+0000

I cant reproduce on PHP5.2.5, seems to have been fixed in 5.2.4 but not tested :

<pre class="highlight">
$a = array('foo'=>'bar');
$arrayobject = new ArrayObject($a,ArrayObject::ARRAY_AS_PROPS);
$arrayobject->foo = 'foobar';
assert($a['foo'] == 'foobar'); // fails on 5.2.5

if you pass a reference $arrayObject (&$a) , then assertion pass (and a logical call-time pass reference warning appears)

Please confirm, I have a patch for that issue (if necessary).

Posted by Darby Felton (darby) on 2008-04-25T09:55:07.000+0000

Actually, this behavior is not documented here:

http://framework.zend.com/manual/en/…

I think now this should be fixed for the next mini-release.

Posted by julien PAULI (doctorrock83) on 2008-04-25T10:05:35.000+0000

I confirm that this is a PHP issue that comes out in PHP <= 5.2.3 (fixed in 5.2.4) please refer to http://bugs.php.net/bug.php?id=42065 for more informations.

So it needs to be patched, and won't BC anything

I'm on it.

Posted by julien PAULI (doctorrock83) on 2008-04-25T11:52:56.000+0000

fixed at r9316

Posted by Wil Sinclair (wil) on 2008-09-02T10:39:40.000+0000

Updating for the 1.6.0 release.

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts