Is it possible to have function calls as parameter defaults in php?
<p>In php, this can be done:</p>

<pre><code>function foo( $var = "bar" ){
    echo $var;
}

foo();         // output : bar

foo("cheese"); // output : cheese
</code></pre>

<p>I've tried to use a function instead like so:</p>

<pre><code>function foo( $var = get_defined_vars() ){}
</code></pre>

<p>Which returned a parse error:</p>

<pre><code>Parse error: syntax error, unexpected '(', expecting ')'
</code></pre>

<p>the obvious answer is the pass the variable like so</p>

<pre><code>function foo( $var ){
    // do stuff
}

foo( get_defined_vars() );
</code></pre>

<p>however, the function is overloadable and can handle many params.</p>

<p>I usually use the function like:</p>

<pre><code>foo( $var1, $var2, $var3 ... etc );
</code></pre>

<p>However I NEED the defined vars from the scope above the <code>foo</code> function, which means EVERYTIME I use the <code>foo</code> function I have to pass <code>get_defined_vars()</code>.</p>

<p>I find it pretty annoying how everytime I want to use this function I have to call <code>get_defined_vars();</code> Like so:</p>

<pre><code>foo( get_defined_vars(), $var1, $var2, $var3 ... etc );
</code></pre>

<p>So PLEASE can anybody think of a way to over come this?</p>

<p>I tried this, also to no avail:</p>

<pre><code>function foo(){
    $args = func_get_args();
    array_unshift( get_defined_vars() );
    call_user_func_array( "bar", $args );
}

function bar(){
    // do stuff
}
</code></pre>
