Edit report at https://bugs.php.net/bug.php?id=39280&edit=1
ID: 39280 Updated by: ni...@php.net Reported by: arendjr at gmail dot com Summary: Support for lazy evaluation type -Status: Open +Status: Closed Type: Feature/Change Request -Package: Feature/Change Request +Package: *General Issues Operating System: All PHP Version: 5.1.6 -Assigned To: +Assigned To: nikic Block user comment: N Private report: N New Comment: Closing as closures are supported as of PHP 5.3 and they can be used to lazily evaluate code. Previous Comments: ------------------------------------------------------------------------ [2006-10-27 15:12:59] arendjr at gmail dot com Description: ------------ This is a feature request for a special language feature in PHP. I'm not sure how hard this feature would be to implement, but given the scripting nature of PHP I can imagine it not being too hard and it would be very useful if PHP6 could support this. What I want to ask for is a new variable type that would support lazy evaluation. I'm not sure what would be a suitable syntax for such a feature, but let's assume for a moment it would use sqaure brackets. This feature would allow someone to write code like: $foo = [1+1]; This statement would basically store the string "1+1" in $foo, and $foo would be marked as being of type "lazy". Only when at some point the value of $foo is being read, the code will be evaluated and the real result will be stored in $foo. So, if someone would subsequently execute the following statement: echo $foo; This would actually expand to: $foo = eval("return (1+1);"); echo $foo; This feature would make it very easy to write code that would conditionally avoid potentially expensive statements. As an example, imagine a case where you have to call some function bar() that takes an argument from which you do not know in advance whether the function will actually use the argument because whether the argument is used depends on some external factor. However, calculating the argument may be a very CPU intensive task. In this case you could write: bar([someVeryExpensiveFunction()]); Thus avoiding the execution of someVeryExpensiveFunction() in the case bar() does not actually use its value. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=39280&edit=1