title: Writing to the return value of a function in PHP
body: <p><a href="https://github.com/php/php-langspec/blob/master/spec/10-expressions.md" rel="nofollow noreferrer">The PHP Language Specification</a> says:</p>
  
  <blockquote>
    <p>A variable is an expression that can in principle be used as an lvalue</p>
  </blockquote>
  
  <p>and</p>
  
  <blockquote>
    <p>The value of a function call is a modifiable lvalue only if the function returns a modifiable value byRef.</p>
  </blockquote>
  
  <p>and the grammar from <a href="https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y" rel="nofollow noreferrer">zend_language_parser.y</a></p>
  
  <pre><code>expr:
     variable T_CONCAT_EQUAL expr
  
  callable_variable:
          simple_variable
              { $$ = zend_ast_create(ZEND_AST_VAR, $1); }
      |   dereferencable '[' optional_expr ']'
              { $$ = zend_ast_create(ZEND_AST_DIM, $1, $3); }
      |   constant '[' optional_expr ']'
              { $$ = zend_ast_create(ZEND_AST_DIM, $1, $3); }
      |   dereferencable '{' expr '}'
              { $$ = zend_ast_create_ex(ZEND_AST_DIM, ZEND_DIM_ALTERNATIVE_SYNTAX, $1, $3); }
      |   dereferencable T_OBJECT_OPERATOR property_name argument_list
              { $$ = zend_ast_create(ZEND_AST_METHOD_CALL, $1, $3, $4); }
      |   function_call { $$ = $1; }
  ;
  
  variable:
          callable_variable
              { $$ = $1; }
      |   static_member
              { $$ = $1; }
      |   dereferencable T_OBJECT_OPERATOR property_name
              { $$ = zend_ast_create(ZEND_AST_PROP, $1, $3); }
  ;
  </code></pre>
  
  <p><strong>So why can't I do this in PHP 7.3?</strong></p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  $a = 'HELLO';
  function &amp;foo() { 
      global $a;
      return $a;
  }
  
  foo() .= ' WORLD';
  echo $a;
  </code></pre>
  
  <pre><code>PHP Fatal error:  Can't use function return value in write context in ...
  </code></pre>
  
  <p>To follow on from this question, with reference to the grammar above: </p>
  
  <p><strong>When is it ok to have a function call on the left hand side of a simple/compound assignment expression?</strong></p>