isset(), undefined variables, and null
- From: arundelo@xxxxxxxxxxx
- Date: Fri, 29 Jun 2007 09:42:46 -0700
Is there a way to tell whether accessing a variable will
result in an "Undefined variable" E_NOTICE? isset() almost
does this, but it also returns false if a variable is set to
null:
$SetNonNull = 0;
$SetNull = null;
var_dump(isset($SetNonNull)); // bool(true)
$Junk = $SetNonNull; // No error, as predicted by isset().
var_dump(isset($NotSet)); // bool(false)
$Junk = $NotSet; // Raises an E_NOTICE, as predicted by isset().
var_dump(isset($SetNull)); // bool(false)
$Junk = $SetNull; // No error -- how to predict?
I realize I could do this by e.g., doing @$Var and checking
afterwards using $php_errormsg or a custom error handler;
I'm hoping for something less klugey.
Thanks,
--
Aaron
http://arundelo.com/
.
- Follow-Ups:
- Re: isset(), undefined variables, and null
- From: gosha bine
- Re: isset(), undefined variables, and null
- From: Andrew Hutchings
- Re: isset(), undefined variables, and null
- Prev by Date: Re: Question re: sql injection
- Next by Date: A small problem in running PHP4 under PHP5 - $row[fieldname]
- Previous by thread: How to copy a dynamic website?
- Next by thread: Re: isset(), undefined variables, and null
- Index(es):