I might come off rather crumudgeonly here, but these last few threads I've
seen going across to
silence notices have a common theme - "I wanna be a lazier coder."

Which is fine - set the PHP error level to not show them.

But don't ask the engine to be rewritten to encourage bad coding practices
which failing to properly initialize variables is a prime example of.  It's
this sort of thinking that got register_globals and magic_quotes put into
the language no doubt. In the long run it's an extremely bad idea and needs
to be avoided.

-1

On Mon, Apr 11, 2011 at 9:36 AM, Etienne Kneuss <etie...@immomigsa.ch>wrote:

> 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