Hi!

> On 6 Dec 2014, at 22:25, Yasuo Ohgaki <yohg...@ohgaki.net> wrote:
> 
> Value is vague term. I would like to use "expression". Expression is
> anything that has value.
> Variables/constants are values that have actual storage.
> Literals are values that may not have actual storage.

The C world already has terminology for this:

* lvalues - values on the left-hand side of an assignment, they can be assigned 
to

  Examples in PHP include:

  * $foo
  * $foo->bar
  * $foo->bar[0]

* rvalues - a superset of lvalues, these are values that can be on the 
right-hand side of an assignment

  Examples include:

  * All the lvalues above
  * 3
  * 2 + 3
  * foobar()
  * $foo + $bar
  * (int)$foo

In C, you (usually) can only get pointers to lvalues, as only lvalues can be 
written to. In PHP, it would make sense only to be able to reference lvalues, 
as only lvalues can be written to. In fact, we (almost?) always treat 
references as if they were assignments, hence why you can reference 
non-existent variables, because you can assign to non-existent variables. AFAIK 
this may be because referencing a value inherently modifies it (in PHP 5 and 
earlier, it sets the if_ref flag, while in PHP 7 it changes it to an 
IS_REFERENCE type). Even if referencing a value didn’t modify it, it allows you 
to do so later.

Doing something like &(2+3) makes no sense as (2 + 3) isn’t a variable, it’s a 
temporary rvalue that is only used once.

As others have said, there is no use-case for allowing assignments to or 
references to rvalues, it’s completely nonsensical. What would make sense is 
adding things like array_top() or array_bottom(), and perhaps allowing NULL 
rvalues to be passed to by-reference parameters with defaults.

Thanks!
--
Andrea Faulds
http://ajf.me/





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

Reply via email to