When my webhost upgraded from PHP 4 to PHP 5, I had
to change this:

if (isset($button)) {
//do something
}

...to this:

if (isset($button) && $button!=NULL) {
//do something
}

1.) Can anyone explain why I had to do that?
2.) Does this have to do with PHP 5?
3.) Will all my isset functions need to be paired with a, "!=NULL" ??
4.) Is there a better way to do this?

The code for the form I used was:
<FORM METHOD="POST" ACTION="nextpage.php">
<INPUT TYPE="submit" NAME="button" VALUE="Submit">
</FORM>

Thank you!!

    You're accessing $button from the form after it's POSTed: you should really be using:

    if(isset($_POST['button']))
    {
       // do something
    }

    $button only works when register globals are set to on (which they probably were before your host made the upgrade). Lucky for you, they're forcing you to write more secure code. Use $_POST to access form variables.

      Thank you for your reply.

      But "register globals" was on in both scenarios.

      Therefore, I still don't understand why I had to have the "!=NULL" part to make the isset work...

        Looks like they may have changed the isset() behavior in PHP 5.2.3. Until then, if a variable was set to NULL, isset() returned false, but now it returns true.

        PS: If you want to return TRUE if $button is set to an empty string or zero, use the "!==" (not identical) operator:

        if(isset($button) && $button !== NULL) {
        

        PPS: If you want it to return false if the variable is not set, or if it is set to NULL, FALSE, zero, or an empty string, then use:

        if(!empty($button)) {
        
          Write a Reply...