Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>A)</strong> To understand what's happening here, one needs to <a href="http://derickrethans.nl/files/phparch-php-variables-article.pdf" rel="nofollow noreferrer">understand PHP's handling of values/variables and references</a> (PDF, 1.2MB). As <a href="http://us.php.net/manual/en/language.references.whatare.php" rel="nofollow noreferrer">stated throughout the documentation</a>: <a href="http://us.php.net/manual/en/language.references.arent.php" rel="nofollow noreferrer">"references are not pointers"</a>; and <a href="http://us.php.net/manual/en/language.references.return.php" rel="nofollow noreferrer">you can only return variables by reference from a function</a> - nothing else.</p> <p>In my opinion, that means, any function in PHP will return a <strong>reference</strong>. But some functions (built in PHP) require <strong>values/variables</strong> as arguments. Now, if you are nesting function-calls, the inner one returns a reference, while the outer one expects a value. This leads to the 'famous' E_STRICT-error <a href="https://stackoverflow.com/search?q=only%20variables%20should%20be%20passed%20by%20reference">"Only variables should be passed by reference"</a>.</p> <pre><code>$fileName = 'example.txt'; $fileExtension = array_pop(explode('.', $fileName)); // will result in Error 2048: Only variables should be passed by reference in… </code></pre> <p><strong>B)</strong> I found a line in the <a href="http://www.icosaedro.it/articoli/php-syntax-ebnf.txt" rel="nofollow noreferrer">PHP-syntax description linked in the question</a>.</p> <pre><code>expr_without_variable = "(" expr ")" </code></pre> <p>In combination with this sentence from the <a href="http://us.php.net/manual/en/language.expressions.php" rel="nofollow noreferrer">documentation</a>: "In PHP, almost anything you write is an expression. The simplest yet most accurate way to define an expression is 'anything that has a value'.", this leads me to the conclusion that even <code>(5)</code> is an expression in PHP, which evaluates to an integer with the value 5.</p> <p>(As <code>$a = 5</code> is not only an assignment but also an expression, which evalutes to 5.)</p> <p><strong>Conclusion</strong> </p> <p>If you pass a reference to the expression <code>(...)</code>, this expression will return a value, which then may be passed as argument to the outer function. If that (my line of thought) is true, the following two lines should work equivalently:</p> <pre><code>// what I've used over years: (spaces only added for readability) $fileExtension = array_pop( ( explode('.', $fileName) ) ); // vs $fileExtension = array_pop( $tmp = explode('.', $fileName) ); </code></pre> <p>See also <a href="http://the-stickman.com/web-development/php/php-505-fatal-error-only-variables-can-be-passed-by-reference/" rel="nofollow noreferrer">PHP 5.0.5: Fatal error: Only variables can be passed by reference; 13.09.2005</a></p>
    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. 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