rfc:ifsetor

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
rfc:ifsetor [2008/06/21 20:38] lsmithrfc:ifsetor [2017/09/22 13:28] (current) – external edit 127.0.0.1
Line 3: Line 3:
   * Date: 2008-06-21   * Date: 2008-06-21
   * Author: Lukas Smith <smith@pooteeweet.org>   * Author: Lukas Smith <smith@pooteeweet.org>
-  * Status: Rejected+  * Status: Declined
  
-This RFC proposes an operator that efficiently implements (isset($foo) ? $foo : $bar) as ifsetor($foo, $bar).+This RFC proposes an operator that efficiently implements (isset($foo) ? $foo : $bar) as ifsetor($foo, $bar). However this proposal has not been accepted, mainly due to the existance of the userland implementation #2. Of course once a true COALESCE() with any number of parameters could be supported, the situation would be different, since obviously using the "hack" of a pass by reference variable would require hardcoding the number of optional parameters.
  
 ===== Introduction ===== ===== Introduction =====
  
 Frequently PHP developers need to initialize some variable that is passed in via the outside to some value. This leads to repeated code, that is needlessly prone to typos as well as some performance overhead. Frequently PHP developers need to initialize some variable that is passed in via the outside to some value. This leads to repeated code, that is needlessly prone to typos as well as some performance overhead.
- +==== Why do we need ifsetor()? ====
-==== Why do we need RFCs? ====+
  
 Frequently developers need to use the following code constructs: Frequently developers need to use the following code constructs:
Line 41: Line 40:
 </code> </code>
  
-Furthermore ifsetor() would support expressions in all but the first parameter, that would only be evaluated if all of the previous parameters were either null or evaluated to null. In the following example the really_expensive_function() should not get called in most cases.+Furthermore ifsetor() would support expressions in the second parameter, that would only be evaluated if all of the previous parameter were either null or evaluated to null. In the following example the really_expensive_function() should not get called in most cases.
  
 <code php> <code php>
 function foo() { return (rand(0, 100) < 100 ? true : null); } function foo() { return (rand(0, 100) < 100 ? true : null); }
-$var = ifsetor($var, foo(), really_expensive_function());+$foo = foo(); 
 +$var = ifsetor($foo, really_expensive_function());
 </code> </code>
  
Line 139: Line 139:
   - The default value can be omitted in which case NULL will be used.   - The default value can be omitted in which case NULL will be used.
  
-http://marcus-boerger.de/php/ext/ze2/ze2-ifsetor-20040416-2.diff.txt (file no longer exists)+http://php.net/~helly/ze2-ifsetor-20040901.diff.txt
  
 ===== Rejected Features ===== ===== Rejected Features =====
Line 178: Line 178:
   * Suggestion to add [[http://marc.info/?l=php-internals&m=113210592810849&w=2|macro]] [[http://marc.info/?l=php-internals&m=116361059402342&w=2|support]] to make it easier to reuse complex userland code pieces to keep the code more readable when handling some of the above aspects in userland   * Suggestion to add [[http://marc.info/?l=php-internals&m=113210592810849&w=2|macro]] [[http://marc.info/?l=php-internals&m=116361059402342&w=2|support]] to make it easier to reuse complex userland code pieces to keep the code more readable when handling some of the above aspects in userland
   * [[http://marc.info/?l=php-internals&m=118946242013246&w=2|Request to add a native function to handle the limited case of a single dimensional array]]    * [[http://marc.info/?l=php-internals&m=118946242013246&w=2|Request to add a native function to handle the limited case of a single dimensional array]] 
 +  * [[http://marc.info/?l=php-internals&m=108955534724882&w=2|Suggestion to fo with the ifsetor() as is]] and later try to find a way to implement a true coalesce() with the name "coalesce()"
rfc/ifsetor.1214080720.txt.gz · Last modified: 2017/09/22 13:28 (external edit)