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++;
}Yes, I believe this is a difference in the way PHP 5 handles object references versus copies now. As per <!-- m --><a class="postlink" href="http://www.php.net/manual/en/language.oop5.basic.php">http://www.php.net/manual/en/language.oop5.basic.php</a><!-- m -->: 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 (<!-- m --><a class="postlink" href="http://www.php.net/manual/en/language.oop5.cloning.php">http://www.php.net/manual/en/language.oop5.cloning.php</a><!-- m -->) it.
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++;
}Yes, I believe this is a difference in the way PHP 5 handles object references versus copies now. As per <!-- m --><a class="postlink" href="http://www.php.net/manual/en/language.oop5.basic.php">http://www.php.net/manual/en/language.oop5.basic.php</a><!-- m -->: 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 (<!-- m --><a class="postlink" href="http://www.php.net/manual/en/language.oop5.cloning.php">http://www.php.net/manual/en/language.oop5.cloning.php</a><!-- m -->) it.