Best way in PHP to ensure in a class that all the class functions are called only if a given condition is true
<p>I have a class in which each function of the class have to check the exact same condition before executing its code:</p>

<pre><code>class myObject
{
    public function function1($argument)
    {
        if($condition === true)
        {
            //Do Something
        }
    }

    public function function2($argument)
    {
        if($condition === true)
        {
            //Do Something
        }
    }

    public function function3($argument)
    {
        if($condition === true)
        {
            //Do Something
        }
    }

    public function function4($argument)
    {
        if($condition === true)
        {
            //Do Something
        }
    }
}
</code></pre>

<p>We can see that function1, function2, function3, function4 only execute their code if <code>$condition === true</code>.</p>

<p>If in the future I add another function called function5, I will have to duplicate this condition.</p>

<p><strong>So my question is, what is the best way to ensure that before call ANY function in the class, a condition is true, and if the condition is false, not call the function.</strong></p>

<p>My method is to use the magic function __call and make all the functions of the class private:</p>

<pre><code>class myObject
{

    public function __call($method,$args)
    {
        if($condition === true)
        {
            call_user_func_array(array($this,$method),$args);
        }

        return;
    }

    private function function1($argument)
    {
            //Do Something
    }

    private function function2($argument)
    {
            //Do Something
    }

    private function function3($argument)
    {
            //Do Something
    }

    private function function4($argument)
    {
            //Do Something
    }
}
</code></pre>

<p>It seems to work. However, I'm unsure that it will always work and that it is a clever way of doing it.</p>
