Hi Den søn. 16. jun. 2019 kl. 01.37 skrev Wes <netmo....@gmail.com>: > > Hi Kalle, I realize it's going to be a bit odd when binding by value. But > it's not that hard to grasp. > > ``` > $a = 123; > $closure = function(){ > use $a; > echo $a; // 123 > }; > $a = 345; > ```
Take this example: function get_closure() { $a = 123; return function() { use $a; echo $a; }; } get_closure()(); $a is not available at this time because the scope of which $a exists in is destroyed at this point, which is why it exists as apart of the prototype like I mentioned and therefore it can be captured. Your idea means we need to scan the body of the declared closure for use statements to perform the binding at this stage, adding extra specialized steps in the executor for only makes me question the motive for this again, and if the motive is that "I'm passing an excessive amount of values to a closure", then I think you are forcing a technique that isn't mean for this to do it anyway. Another thing to take into consideration here is the performance impact that it can potentially have. Whether or not its at the top of the body or separated in multiple statements or all over the body still means we need to check if the body contains such a statement and do the right computations for it, I still don't think the argument presented in the RFC justifies this potential cost, and would like to see a demo implementation and impact it would have first. -- regards, Kalle Sommer Nielsen ka...@php.net -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php