Article

The PHP Anthology Volume 1, Chapter 1 - PHP Basics

Page: 1 2 3 4 5 6 7 Next

Chapter 1: PHP Basics

In this first chapter, I'll assume you've had a basic grounding in PHP, such as that provided in the first few chapters of Kevin Yank's Build Your Own Database-Driven Website Using PHP & MySQL (ISBN 0-9579218-1-0), and instead concentrate on the essentials of "getting around" in PHP.

In this chapter, you'll find out where to get help—a defence against those that bark "Read the manual!" at you—and how to deal with errors in your code. We'll also discuss some general tips for keeping your code portable, and provide other essential roughage for your PHP diet. Not everything here fits under the heading of "basic"—there may also be a few surprises in store for the more experienced PHP developers, so keep your eyes peeled!

Be warned, though, that the discussion of PHP syntax is not the most invigorating of subjects—although it is essential to prepare for later chapters. If you start to struggle, remember the line from The Karate Kid: you must learn "wax on, wax off" before you can perform the flying kick.

Where do I Get Help?

PHP is the most widely-used Web scripting language, running on over ten million domains around the world. For an open source technology that lacks any corporate funding whatsoever, its popularity may seem inexplicable. Yet PHP's success is no mystery; it has one of the most active and helpful online communities of any technology. Recent estimates place the number of PHP developers worldwide at around 500,000 and given the nature of the medium, it's fair to assume that a large proportion are active online. In other words, for developers of PHP-based Websites, help is only ever a few clicks away.

Reading the Manual

There's a well known four letter abbreviation, RTFM (I don't think it needs explaining here), which tends to be used to harass beginners in all areas of computing. While I can understand veterans might be unwilling to repeat endlessly the same, well documented instructions, I think the basic assumption should be that we all know how to read the manual in the first place.

The documentation for PHP is excellent, and is maintained by volunteers who make it their sole purpose to keep it up to date, understandable and relevant. The online version is extremely easy to navigate and contains further know-how in the form of annotations from developers across the globe. The manual is one of the areas in which PHP is truly exceptional; software houses like Sun and Microsoft still have a long way to go to provide this quality of material to developers working on their platforms.

The manual is also available in twenty-four different languages but as you're reading this book I'll assume you're happy with the English version of the manual. It's broken down into five main sections plus appendices. It's worth knowing what kind of information can be found, and where—at least within the first four sections, which are the most relevant to the typical PHP developer.

Section I: Getting Started

http://www.php.net/getting-started

This section provides a short introduction to PHP with some basic examples. It then explains how to install PHP (describing all sorts of operating system-Web server combinations), and how to configure it in terms of modifying your php.ini file.

Not to be overlooked is the section on security, which covers the areas in which PHP developers often make mistakes that leave their applications open to abuse. Once again, the "price" of PHP's ease of use is that it won't always protect you from your worst mistakes, so it's worth getting started on security as early as possible in your PHP career. You'll find a summary of key security issues in Appendix C, Security Checklist, as well as in discussions throughout this book, where appropriate.

Section II: Language Reference

http://www.php.net/langref

This section covers the fundamentals of PHP as a programming language. Some of these are essential to your being able to achieve anything with PHP, while others become useful as you look for ways to improve your technique. Reading the whole lot in one sitting may well be like reading a dictionary. Fortunately, it's possible to absorb much of the information contained in the language reference by reading the wealth of tutorials available online, and examining the code that's used in open source PHP applications. Certainly, as you read this book, I hope you'll pick up a thing or two about getting the most out of PHP. However, it is worth familiarizing yourself with the subjects contained in this section of the manual, and keeping them in the back of your mind for future reference.

Section III: Features

http://www.php.net/features

Covered here are the core elements of PHP that are generally focused on solving specific Web-related problems. Much of the Features section reads like an "executive summary" and, from a developers point of view, the information contained here may be better understood when you see it in action—for instance, in the examples we'll see throughout this book.

Section IV: Function Reference

http://www.php.net/manual/en/funcref.php

This section makes up the real body of the manual, covering all aspects of the functionality available within PHP. This is where you'll spend most of your time as you progress with PHP, so you'll be glad to hear the PHP group has made a concerted effort to make this section easy to get around. It's even fun, in an idle moment, just to trawl the manual and be amazed by all the things you can do with PHP. Yes, I did just describe reading a manual as "fun"!

The function reference is broken down into subsections that cover various categories of functions, each category corresponding to a PHP extension.

If you liked this article, share the love:
Print-Friendly Version Suggest an Article

Sponsored Links