#39280 [NEW]: Support for lazy evaluation type

From: Date: Fri, 27 Oct 2006 15:12:59 +0000
Subject: #39280 [NEW]: Support for lazy evaluation type
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-104073@lists.php.net to get a copy of this message
From: arendjr at gmail dot com Operating system: All PHP version: 5.1.6 PHP Bug Type: Feature/Change Request Bug description: Support for lazy evaluation type 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 bug report at http://bugs.php.net/?id=39280&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=39280&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=39280&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=39280&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=39280&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=39280&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=39280&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=39280&r=needscript Try newer version: http://bugs.php.net/fix.php?id=39280&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=39280&r=support Expected behavior: http://bugs.php.net/fix.php?id=39280&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=39280&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=39280&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=39280&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=39280&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=39280&r=dst IIS Stability: http://bugs.php.net/fix.php?id=39280&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=39280&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=39280&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=39280&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=39280&r=mysqlcfg

« previous php.bugs (#104073) next »