For variables, it's not very useful. For expressions, might allow to
avoid some boilerplate code - for the same reason we allow expressions
in function calls - we might ban that, and have people assign
expressions to variables and then use variables for function calls, but
we recognize it is not nice.

Help me understand, b/c I am not clear what you mean by "we allow expressions in function calls". This is my immediate understanding of the anatomy of a closure:

  // in some non-global scope

  $x = function (/* call scope */) use (/* declaration scope */) {
      global $foo; // global scope
      $this->... // scope of parent object, or bindTo()

      // variable scoping resolution / symbol table creation:
      // declaration time, call time, then variables
      // inside the method body.

  }

Having an expression in use() is not immediately clear when that might execute, would it execute at declaration time? Or at call time? If the result of the expression is an object, does this mean it is bound by reference, or a copy from declaration time? (Currently, we use "use (&$foo)" to ensure declaration time variables are bound by reference if they are not objects, and this works well, even though it's not immediately apparent).

By "we allow expressions in function calls", I understand that if you mean:

  $x = do_something($foo->bar());

That makes sense, but if you mean this:

  function do_something($foo->bar()) {}

That does not. Are you saying there is another place in PHP where during declaration time of some kind of type/structure we evaluate expressions?

$fileReturnsFunction and that would work too).  So, if that was a bad
variable name 2 lines earlier, why not just change the variable name for
both scopes?

It's not about variable names, as I see it. Just renaming is not very
useful. Having expression there is useful, for the reason described above.


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to