Re: Problem with Object references in an array via for loop
| From: | David Moylan | Date: | Thu, 29 May 2008 20:21:39 +0000 |
| Subject: | Re: Problem with Object references in an array via for loop | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-274837@lists.php.net to get a copy of this message | ||
Solved this. I tried setting a class variable directly and didn't have the same issue (should have tried that long ago). So that told me that my error was somewhere in some lower level code when I initialize my objects. I tracked it down to a problem where I wasn't cloning properly when I needed to (since PHP4 passes by value, and 5 by reference).
Sorry for the bandwidth and thanks for the help.
Dave
Robert Cummings wrote:
On Thu, 2008-05-29 at 14:01 -0300, Gabriel Sosa wrote:try doing this $secs = array(); foreach($_GET['sids'] as $sid){ $obj = null; $obj = new CustomSecurity(); $obj->set(array('customSecurityID' => $sid)); $secs[] = $obj; }No, no, no. If it's a reference issue you need to do the following: <?php $secs = array(); foreach($_GET['sids'] as $sid) { unset( $obj ); $obj = new CustomSecurity(); $obj->set(array('customSecurityID' => $sid)); $secs[] = $obj; } ?> Assignment of null won't break a reference, it'll just make the value refer to null. You need unset to break the reference. Personally, I'd like to see the class definition to see what happens inside the set() method. Cheers, Rob.