Calling context (array or scalar) in PHP?
<p>Is it possible for a function or method in PHP to determine whether the caller expects an array return value or not (ala Perl's <code>wantarray</code> operator)? Specifically, I'd like to create a <code>__get()</code> magic method that automatically returns an array if the caller expects one, and a sensible scalar value if not. So something like this:</p>

<pre><code>public function __get($name)
{
    if (wantarray())
    {
        // data is stored internally as an array of arrays
        // return appropriate array as-is
        return $this-&gt;data[$name];  
    }
    else
    {
        // caller doesn't expect an array, return imploded string instead
        return implode(', ', $this-&gt;data[$name]);
    }
}
</code></pre>

<p>Basically, does PHP have an equivalent to Perl's <code>wantarray</code> operator or otherwise allow for the determination of this sort of calling context?</p>
