> I think allowing globals/lexicals to be passed by value doesn't make
> much sense, you could just use a regular parameter for that.

No, that is highly inconvenient when you're doing actual functional 
programming with higher order functions and everything.

$i = 1;
$incrementor = lambda ($x) lexical ($i) { return $x + $i; }
...
$arr = array_map($incrementor,$arr);

How would you do this by passing in $i as a parameter without a closure?
And if you use references, this may break if $i is a loop variable (the 
canonical example of closure-WTF).

> And that  would bring another inconsistency to PHP, and would mean that PHP
> is discouraging the use of $_GLOBALS, that was created to discourage to use
> of 'global $var'.

All languages accumulate cruft as they evolve.
global behaves in a manner that is inconsistent with pretty much everything 
else in PHP (referencing by default), and variables can be declared global in 
the middle of a function, which makes no sense at all. It would be a mistake 
to be consistent with something so badly broken.

By "long term replacement for global" I meant to imply that it would actually 
be a good idea to remove the old global keyword from the language. Deprecate 
it in PHP 6 and kill it in PHP 7, or maybe in PHP 7 and 8. Cruft gone.

$GLOBALS should be kept around because it is not a reference and allows 
acutally unset()ing a global variable, for example.

Gesundheit
  Wag

-- 
Da saß ich nun, führte Krieg und hatte Geburtstag.
 - Joschka Fischer

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

Reply via email to