I try to create some sort of setup class, like global values for the page.
The PHP-code
class globals
{
public $page;
public function __construct()
{
}
public function set_page($value)
{
$this->page = $value; // Maybe from a database
}
}
class get
{
public function page()
{
$globals = new globals();
return $globals->page;
}
}
$globals = new globals();
$globals->set_page('My value');
echo get::page(); // Short function to be in a template
Question
- My class forget the value I set. Why is that?
- Do I have to use global variables?
- Is this the correct approach for the problem?
Not, if your can use PHP 5.3
Better to use a generic class for this, or use static properties of objects
P.S.
But this is not a nice approach