I have a small problem - I want to decrease code duplication in my site, and the best way that I can see of doing that is to remove a lot of unnecessary instances of variable setting.
One of the most common is the $baseUrl variable, which contains the http host and php self values, for convenience. However, I have to set it for each function:
class Site
{
function outputPage()
{
$baseUrl = "http://". $_SERVER['HTTP_HOST'] . rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
}
}
This is then typically included in any links that the site uses:
echo '<a href="' . $baseUrl .'/article/jun/example11/">Example 11</a>';
It's set around six times throughout the class, once per function that needs it - is there any way to set it once and then allow all the functions to access it?