Re: Problem with Object references in an array via for loop

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux