Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This behavior could be classified as <strong>bug</strong>, so you should definitely not rely on it.</p> <p>The (simplified) conditions for the message <strong>not</strong> to be thrown on a function call are as follows (see the <a href="http://lxr.php.net/search?q=ZEND_SEND_VAR_NO_REF&amp;project=PHP_5_3" rel="nofollow">definition of the opcode <code>ZEND_SEND_VAR_NO_REF</code></a>):</p> <ul> <li>the argument is not a function call (or if it is, it returns by reference), and</li> <li>the argument is either a reference or it has reference count 1 (if it has reference count 1, it's turned into a reference).</li> </ul> <p>Let's analyze these in more detail.</p> <h3>First point is true (not a function call)</h3> <p>Due to the additional parentheses, PHP no longer detects that the argument is a function call.</p> <p>When parsing a <a href="http://lxr.php.net/xref/PHP_5_3/Zend/zend_language_parser.y#non_empty_function_call_parameter_list" rel="nofollow">non empty function argument list</a> there are three possibilities for PHP:</p> <ul> <li>An <code>expr_without_variable</code></li> <li>A <code>variable</code></li> <li>(A <code>&amp;</code> followed by a <code>variable</code>, for the removed call-time pass by reference feature)</li> </ul> <p>When writing just <code>get_array()</code> PHP sees this as a <code>variable</code>.</p> <p><code>(get_array())</code> on the other hand does not qualify as a <code>variable</code>. It is an <code>expr_without_variable</code>.</p> <p>This ultimately affects the way the code compiles, namely the extended value of the opcode <code>SEND_VAR_NO_REF</code> will no longer include the flag <code>ZEND_ARG_SEND_FUNCTION</code>, which is the way the function call is detected in the opcode implementation.</p> <h3>Second point is true (the reference count is 1)</h3> <p>At several points, the Zend Engine allows non-references with reference count 1 where references are expected. These details should not be exposed to the user, but unfortunately they are here.</p> <p>In your example you're returning an array that's not referenced from anywhere else. If it were, you would still get the message, i.e. this second point would not be true.</p> <p>So the following very similar example <em>does not work</em>:</p> <pre><code>&lt;?php $a = array(); function get_array() { return $GLOBALS['a']; } return reset((get_array())); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload