Re: Problem with Object references in an array via for loop
| From: | Robert Cummings | Date: | Thu, 29 May 2008 17:47:03 +0000 |
| Subject: | Re: Problem with Object references in an array via for loop | ||
| References: | 1 2 3 4 5 6 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-274826@lists.php.net to get a copy of this message | ||
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.
--
http://www.interjinn.com
Application and Templating Framework for PHP