I’m trying to use global variable across a class.
Basically, the function render($html, $pageTitle); is called.
Within that class, exists functions such as buildHeader($pageTitle) which looks like this:
private static function addHeader($pageTitle){
global $pageTitle;
$html = self::capture_output('header.inc');
return $html;
}
within header.inc, I define the variable $pageTitle as global, however, it’s not echoing the variable.
I’m also not getting errors that the variable has not been defined / initialised.
the render function calls the private methods, such as addHeader to build the page content.
You cover $pageTitle by function argument. Also you should rather use
$_GLOBALS['pageTitle'];instead of usingglobalwhich makes code more clear and helps avoid such conflicts you have. also, I quite believe you should rather move yourglobal $pageTitle;tocapture_output()function, where it seem to be used, instead of keeping it inaddHeader()where it got no effect.