That would satisfy some of the requested feature, but try
calling ifsetor($my_array['bad key'], functionWithSideEffects()).
Marcus has repeatedly mentioned that the requested feature is
hard (bordering on impossible) to implement, but in the requested
feature (if I understand it (and it is what I would ask for too :) )),
there would be no error for using a key that isn't in the array,
there would be no side effect of creating a key in the array, and
if the $my_array['bad key'] actually did happen to be non-NULL,
the function with the side effects wouldn't get called.

That would be really handy, especially if it could take a variable
number of arguments.  Using a standard name like coalesce would
be nice.

BTW, I have no weight around here; just thought I could help
clarify, having following this thread with interest...

- Todd

On Fri, 2004-07-09 at 12:07, Cris H wrote:
> Isn't this problem solvable with just a "User Space" function?
> 
> <?php
> 
>     error_reporting(E_ALL);
> 
>     function ifsetor(&$variable, $alternate = NULL){
>         if(isset($variable)){
>             $tmp = $variable;
>             echo('<p>$variable exists.</p>');
>         }
>         else{
>             $tmp = $alternate;
>             echo('<p>no $variable here.</p>');
>         }
>         return $tmp;
>     }
>     
>     // no errors thrown ...
> 
>     $nonexistent = ifsetor($nonexistent);
>     ifsetor($randomNonexistent);
>       
>     if($nonexistent !== NULL)
>         echo('<p>$nonexistent is NOT NULL</p>');
>     else
>         echo('<p>$nonexistent is NULL</p>');
> 
> ?>
> 
> Because, as Derick Rethans mentioned, arguments passed by
> reference will not trigger the Undefined (variable | index)
> Notice at the point of the function call, and also PHP's C++
> style default arguments providing the alternate value, surely
> the above code would suffice?
> 
> Apologies if I've completely misunderstood (with certainty a
> non-zero probability)...
> 
> Regards,
> 
> Cris
> 
> 
>       
>       
>               
> ___________________________________________________________ALL-NEW Yahoo! Messenger 
> - sooooo many all-new ways to express yourself http://uk.messenger.yahoo.com

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

Reply via email to