Skip to Content
PHP & MySQL® Web Development All-in-One Desk Reference for Dummies®
book

PHP & MySQL® Web Development All-in-One Desk Reference for Dummies®

by Janet Valade, Tricia Ballad, Bill Ballad
January 2008
Intermediate to advanced
672 pages
14h 51m
English
For Dummies
Content preview from PHP & MySQL® Web Development All-in-One Desk Reference for Dummies®

1.4. Writing PHP Code

PHP code must be read by humans, as well as by the PHP software. PHP scripts are written by humans and must be modified, updated, and maintained by humans. The script might need to be modified a year or two in the future when the original programmer has moved on to retirement on a tropical beach. The person who must modify the script needs to be able to read and understand the script, which he or she has never seen before. Consequently, the PHP code must be written in a style that's easy for humans to comprehend quickly.

In general, each PHP simple statement is written on a single line ending with a semicolon. An exception is echo statements that echo long text strings. It's not necessary to end the statement at the end of a line and start a new statement on the next line. You can write the statement over several lines, as long as you're careful to end the statement with the semicolon on the last line. It's also a good idea to indent the lines after the first line to show clearly that the additional lines are part of the same statement, as follows:

echo "This is a really,
  really, really, really
  long statement";

When writing blocks of statements, coding style dictates that you should indent the block statements to clearly show where the block begins and ends. For instance, in the following example of a conditional statement, the simple statements in the block are indented:

if(the sky is blue)
{
  put leash on dragon;
  take dragon for a walk in the park;
}

PHP ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

PHP and MySQL® Web Development, Fifth Edition

PHP and MySQL® Web Development, Fifth Edition

Luke Welling, Laura Thomson
PHP 8 Basics: For Programming and Web Development

PHP 8 Basics: For Programming and Web Development

Gunnard Engebreth, Satej Kumar Sahu

Publisher Resources

ISBN: 9780470167779Purchase book