Have a variable exist in all functions of a class?
<p>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.</p>

<p>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:</p>

<pre><code>class Site
{
function outputPage()
{    
$baseUrl = "http://". $_SERVER['HTTP_HOST'] . rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
}
}
</code></pre>

<p>This is then typically included in any links that the site uses:</p>

<pre><code>echo '&lt;a href="' . $baseUrl .'/article/jun/example11/"&gt;Example 11&lt;/a&gt;';
</code></pre>

<p>It's set around six times throughout the class, once per function that needs it - is there any way to set it <em>once</em> and then allow all the functions to access it?</p>
