Oh, for a "sureset()" (orthogonal to isset())

weston_at_leary.csoft.net
Date: 10/30/03


To: php-general@lists.php.net
Date: Thu, 30 Oct 2003 14:31:01 -0500 (EST)

I'm sure I'm not the first person to find strict checking of whether
or not variable (or array index) is set painful. I've considered
just setting error_reporting() to some lax level on every script I
write for the rest of my life, but have been thinking there might
be a better way.

What I'd like is a "sureset()" function ...there's probably a better
name, but what it would do is more important:

function sureset($var) {

        if(!isset($var) || empty($var))
                return '';
        else
                return $var;
}

Of course, when you've got strict checking on, the above doesn't
work, because if the variable is unset you get caught on the fact
before the function call happens.

Is there something like this already? Is there a way to make this
work? Or should I just go back to the idea of nuking error_reporting
in all my scripts?

Thanks,
        Weston

Thanks,



Relevant Pages

  • Re: Critcize my scripts.
    ... > (I know it's a good practice to put use strict in Perl ... > use strict.The script below work fine if I comment out ... perldoc -f use ... Sub Routines ...
    (perl.beginners)
  • Re: [PATCH] Speed up "make headers_*"
    ... 'use strict' and 'use warnings' is recommended. ... The parentheses are not needed for most of the built-in functions. ... More or less the same comments would apply to the next script as well. ...
    (Linux-Kernel)
  • Re: tricky list comparison problem
    ... > I'm having a bit of an issue with a script I'm working on. ... > - 69078878" as available sectors. ... > use strict(); ... You are telling perl to load the 'strict' module and then you are telling the ...
    (perl.beginners)
  • Re: Regular Expression and file editing.
    ... Goksie wrote: ... If i run the script, the changes could not be effected bcos the files is ... use warnings; ... use strict; ...
    (perl.beginners)
  • Re: Passing vars to a "require"d script
    ... > require'd script didn't seem to pull in the form data, ... >> use strict; ... >> use warnings; # main program ...
    (comp.lang.perl.misc)