On Apr 10 21:22:58, D. Dante Lorenso wrote:
> The problem with implementing "ifsetor", "filled", or "??" in userland 
> is that the "not set" or "undefined" warning is fired before the 
> variable is passed to the underlying function/method.
> 
> Is it possible to add a modifier that turns off warnings for undefined 
> variables whenever that specific method is called?  Something like:

Short answer is no. See below.

> 
> class Utility {
>    public silent function filled() {
>      $args = func_get_args();
>      foreach ($args as $arg) {
>        if (!empty($arg)) { return $arg; }
>      }
>      return false;
>    }
> }
> 
> $x = Utility::filled($my_undef, $x['undef'], $nosuch, 'default');
> 
> The modifier "silent" will turn all undefined or "not isset()" variables 
> into NULL values when being passed to the method and no warnings will be 
> issued.

This is not really possible without some major changes. You've to
understand that arguments are evaluated before the function/method call.
The notices are thus emited before even considering the function/method
call.

This is exactly why isset and empty are not functions, but language
constructs, so that they can work with variables in a special way.

> 
> Then, we can build our own damn functions as we see fit without the fuss.
> 
> -- Dante
> 
> -- 
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

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

Reply via email to