PLEASE note: These pages are here solely for historic purposes. New articles have not been written since 2001; many links in the index are broken; and most ahref.com email addresses will now bounce. Try visiting ep Productions, Incorporated, the web programming and development company behind this site.

Tip: In search of books on web development? Try the bookstore.

web index ahref.com: a community space for web developers------ -----
IndexToolsCareersTalk
ahref.com > Guides > Technology
Technology Guide


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.

continue reading >>>
or jump to a topic:

Zero Is Empty
Setting Cookies and Quoting {$
Break/Continue, Unset, and the Rest

view a printable version of this article


To suggest a topic, please email info@ahref.com.

 


HOME ||| ABOUT AHREF.COM ||| ADVERTISE ||| FEEDBACK ||| SEARCH THIS SITE ||| CONTRIBUTE

This site © 1998-1999 ep Productions, Inc. Text of any articles is copyright of the author. All rights reserved. Terms of use.