Debugging PHP: Did You Remember to "Dot All Your I's and Cross All Your T's"?
October 2, 2000
So you finally managed to install PHP and are now ready to conquer the web.
You type: <? phpinfo(); ?>
and get the pretty "Hello World from PHP". All anxious
to put your new tool to use you find the print function in
the manual,
write your own hello
world, load the page and then it hits you: Parse error: parse
error in /usr/local/apache/htdocs/test.php on line 2
|
You didn't think you were going to slip right into PHP without going
through the compiler/parser initiation process, did you?
Don't worry, we have the
"Coles Notes" on common newbie problems and
errors. We will start
with general syntax errors, move on to runtime errors and conclude with
tips on the infamous logical errors and some last resort
links to visit when all else fails. The end of this article features a
bulleted checklist to consult in case of errors. Print it and keep it
by your side for those gloomy Sunday nights before
the deadline. Many have
spent hours banging their heads against their monitors so why should you
(it's an expensive habit).
PHP automatically instantiates variables which means
that you do not have to
formerly declare them. A process called "autovivification".
This is both a blessing and a curse. You don't have to worry about
declaring every single variable at the top of your program (as you would
in "C") but you do have to worry about
misspelling your variable
names and accidentally declaring new ones. Some languages, such as
Perl, keep
track of variables used
only once and given the proper runtime options will
warn you. Additionally
Perl offers a very functional debugger. PHP development as of PHP 4.0.2
has not yet matured to this stage. A debugger was in development in
previous PHP versions. It was last available in php3 CVS and is NOT
available in PHP 4 - 4 CVS. The source has all references to the
deugger_on function as php3 functions.
Do not let the debugger absence discourage you from PHP programming. PHP
offers a wide range of functions you would expect from mature languages
such as "C". Personally I find PHP one of the easiest and most
"Web Functional" programming languages.
Contents:
Every sentence must end with a period
Spelling mistakes give you a few gray hairs
MySQL and PHP: They have some "TWERPS" of their own
Make your PHP programming life easier
Time to proofread your code - The Checklist
Every sentence must end with a period - Page 2
|