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

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

 



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


-- 
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