PHP 3 and 4 Incompatibilities: A Closer Look
08/15/2000
by Edward Piou
Earlier this year, the PHP team released PHP 4.0, the latest major version of PHP: Hypertext Processor, a popular and useful server-side scripting system. The new version of PHP is supposed to be faster, more reliable, and just better all-around. In addition, it should be, for the most part, downwards-compatible with PHP 3. A quick list of incompatibilities (and there aren't many) is available at the PHP web site.
This article looks at some of the more interesting incompatibilities in-depth, and explores the type of code which you may have problems with if you try to move it from PHP 3 to PHP 4. I've included workarounds for several of the incompatibilities; some of which may be obvious, but some of which (hopefully) will help in any debugging you have to do. Inc. #1 - the string '0' is considered to be empty
This could be a big problem, depending on how often (and how) you check for the existence/truth value of variables which might have a string value of "0". For example, if you're checking to make sure the user chose one of the checkbox or radio values on a form with code like:
if ($check_val) {
process_val ($check_val);
}
else {
print "<br>Please check one of the boxes.\n";
}
and a valid value for the checkbox was "0", you'll have problems (since PHP passes the checkbox value through as a string). if ($check_val) will come out false, even though the value is set, and is not (really) false.
To fix this, use the isset() function, which returns true if a variable is set/exists, false otherwise:
if (isset ($check_val))
process_val ($check_val);
}
else {
...
I'm expecting this to be the biggest problem with moving my own code.
|