Make your PHP programming life easier - Page 5
October 2, 2000
Get an editor which offers bracket matching and syntax highlighting.
Many popular editors such as Emacs, vi and Nedit offer add-on modules for
PHP syntax highlighting. My favorite,
NEdit is very light and
configurable. Additionally it is available for both Windows and XWindows.
To run the windows version you need an XWindows emulator such as eXceed.
Some of the other editors I saw mentioned include:
Time to proofread your code - The Checklist
Before I proceed with the checklist I'd like to be clear on the origin of
this list. As a regular reader of the PHP General and DB mailing lists I've
seen may attempts at assembling a list to solve the common and frequent
problems that appear on the mailing list. The following list contains
information gathered from the mailing list, input from many users on the
list and my own personal two cents. It is in no way complete and you may
use it as you see fit.
- Check the (),[] and {}'s. They should be a pair.
- Check the strings. "" inside a "" string doesn't work
unless you escape them with a \ (\") instead.
- Check for typos in reserved words. myslq_num_rows() doesn't work.
mysql_num_rows() does.
- Use the manual at www.php.net/manual, a local mirror etc., to check
your syntax.
- Remember to include global statements if you want to use global
variables in a function.
- If you want to set cookies with setCookie() or an equivalent, ensure that
you have not output ANY characters. This includes whitespace before
starting <? or <?php. <? must be the first thing in your program.
- If SQL queries fail, write them out with echo or print, and check
the syntax. Especially if you have included $variables in the statement.
- If the statement looks all right, try the query with your DB query
tool such as the mysql commandline tool.
- If it still won't work - check if you have granted the db user the
right access.
- If you are getting "can't redeclare foo()" you've probably
included a file twice. Use include_once() to prevent it.
- Remember the case-sensitivity. $Foo may not be the same as $FOO.
- It's $this->foo() and $this->variable. Not $this->$foo() and
$this->$variable.
- When the manual just won't cut it. Try #php on EFNet, there's always a
bunch of helpful guys/girls around.
- Consult the PHP mailing list archives, chances are someone already had the
same problem. The archives are accessible as a part of the search function
on the PHP site.
When all else fails you should consult the PHP General mailing list. You
may subscribe on www.php.net or you may read the newsgroup version of the
list. Be warned, at the time of writing, this list receives well over a
100 messages every weekday. Post your question with a descriptive subject
line and wait for a response. Don't post a message with a subject like
"WHAT'S WRONG WITH THIS CODE" or "HELP ME!". It's
just a question of etiquette. In your message indicate what you think
the problem is and what you've done so far to try and solve the problem.
Additional Resources:
PHP Manual
Perl
database
PHP Classes
NEdit
PHPEdit
PHP Editor list with reviews
MySQL and PHP: They have some "TWERPS" of their own - Page 4
Debugging PHP: Did You Remember to "Dot All Your I's and Cross All Your T's"?
|