Stut wrote:
Jim Lucas wrote:
Richard Kurth wrote:
What do you do when isset does not work? If I send data in a
$_REQUEST['var'] like if (isset($_REQUEST['var'])) {
}
Put var has no data it still says it is set. Because $_REQUEST['var']
= ""
and isset thinks "" is set
I use this combination a lot:
if ( isset($_GET['something']) && !empty($_GET['something']) ) {
// do something here with $_GET['something']
}
The isset is a pointless waste of cycles.
-Stut
well, as the OP said, he wants to know when the variable has a value other the "".
So, to check for that you have to do something like this right?
if ( $var != '' ) {}
if ( strlen($var) > 0 ) {}
if ( !empty($var) ) {}
... a number of other ideas come to mind, but
none of them will work, because they will always product a E_NOTICE warning.
You COULD always use empty() prefixed with an @ to quiet the E_NOTICE,
but, me, I could/would possibly miss that when scanning the code.
I would however see the isset() && !empty() bit of code.
And the amount of time that you save by not using isset(), well, lets just say that if it affected
the time of your apps performance, I think you have other things to worry about first.
Just for example. The current project that just took over has about 60,000 lines of code. Doing a
quick grep -ri 'isset' * on the dir returns about 475 instances of that function call. Many of
which I have added to the system to get rid of E_NOTICE warnings, for the simple fact that I wanted
to set error reporting to E_ALL. Bad mistake, over half the scripts fire off warnings left and
right, because all he was doing for checking was !empty() if ( $var ) {} or if ( $var != '' ) {}
calls all over the place.
There are two ways that I have found to get rid of the notices.
Example #1
if ( isset($_GET['something']) && !empty($_GET['something']) ) {
// do something here with $_GET['something']
}
Example #2
if ( @!empty($_GET['something']) ) {
// do something here with $_GET['something']
}
Other suggestions would be gladly accepted.
--
Enjoy,
Jim Lucas
Different eyes see different things. Different hearts beat on different strings. But there are times
for you and me when all such things agree.
- Rush
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php