Click to See Complete Forum and Search --> : functions in php5 not like php4?


pinkcow
05-17-2007, 08:12 PM
hi

why does the function overwrite $db? in php4 the parameter is copied and not passed by reference.


function renderNews($db, $tbl, $path, $freetag, $markUp) {
$db->q("select txt from ".$tbl['cat']." where ".substr($query,0,-4));
while($db->nr())
$cat .= $db->r['txt'].' / ';

$tmp .= substr($cat,0,-2).'</td>';

return $tmp;
}

$db->q($query);
while($db->nr()) {
echo renderNews($db, $tbl, $path, $freetag, $markUp);

$i++;
}

NogDog
05-17-2007, 09:04 PM
Yes, I believe this is a difference in the way PHP 5 handles object references versus copies now. As per http://www.php.net/manual/en/language.oop5.basic.php: When assigning an already created instance of a class to a new variable, the new variable will access the same instance as the object that was assigned. This behaviour is the same when passing instances to a function. A copy of an already created object can be made by cloning (http://www.php.net/manual/en/language.oop5.cloning.php) it.