demosthenes.info

A blog by Dudley Storey on , , , , , , and anything else that strikes his fancy.

featured articles

popular favourites

How To Avoid Problems In PHP

  1. Don’t try to do everything at once. Write a little bit of code, then test it. Write a little bit more, and test it again. Don’t start writing a full page of code and expect it to run. When errors happen, it’s a lot easier to solve them if you know where they are happening.

  2. Put comment “traffic cones” in your code to narrow down problem areas. Comments in PHP are exactly the same as those in CSS: i.e.

    1. <?php This code will be run;
    2. /* this code will
    3. be ignored (multiple lines) */
    4. // this code (a single line) will be ignored too
    5. # this code (again on a single line) will also be ignored
    6. ?>

    In class your instructor will not respond to cries of “it doesn’t work”. Before I will help you I expect you to tell me where the code doesn’t work, by eliminating suspect code inside comments. In doing so, you’re likely to find the cause of the problem yourself.

    Keep in mind that the PHP parser is sometimes inaccurate when reporting the locations of errors. Sometimes it will report “Error on line 1” when the error isn’t on line 1 at all (in fact this error usually indicates that a brace has not been closed correctly).

  3. Close code correctly. Problems coding HTML are usually due to incorrectly written tags and incorrectly closed tags. If this is the source of most of your errors in HTML, the same problems will continue to haunt you when coding PHP.

web developer guide

featured comment

by JoelB in Goodbye, JQuery Validation: HTML5 Form Errors With CSS3

what i'm reading

A Storm of Swords: A Song of Ice and Fire: Book Three
A Storm of Swords: A Song of Ice and Fire: Book Three

what i'm watching

Californication: The Third Season
Californication: The Third Season

what i'm playing

Mass Effect 3 Collector's Edition
Mass Effect 3 Collector's Edition

what i'm hearing

Dub FX
Dub FX

blogs

podcasts

no ads ever

This blog is free of advertising, and always will be.

creative commons licensed

The content of this blog is free to use in whatever way you wish under the Creative Commons license.