Passing Object as default function parameter.
Posted: Wed Feb 06, 2008 9:45 am
Hello. Question about passing existing objects as parameters to functions. Example.
Now there are like 20 pages that calls the getPageHeader function as the title varies from page to page. However the DB object is constant so is there a way to set it as a default value in the getPageHeader function instead of having to do " getPageHeader($title, $db); " on all the pages.
thanks in advance
/Daniel
Code: Select all
/* create datbase connection */
$db = new db();
function getPageHeader($title, $db) {
include('header.php');
}
$title = "this is a page";
getPageHeader($title);
/*then the rest of the page */
thanks in advance
/Daniel