05.05.2013 Views

Programming PHP

Programming PHP

Programming PHP

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 2 CHAPTER 2<br />

Language Basics<br />

This chapter provides a whirlwind tour of the core <strong>PHP</strong> language, covering such<br />

basic topics as data types, variables, operators, and flow control statements. <strong>PHP</strong> is<br />

strongly influenced by other programming languages, such as Perl and C, so if you’ve<br />

had experience with those languages, <strong>PHP</strong> should be easy to pick up. If <strong>PHP</strong> is one of<br />

your first programming languages, don’t panic. We start with the basic units of a<br />

<strong>PHP</strong> program and build up your knowledge from there.<br />

Lexical Structure<br />

The lexical structure of a programming language is the set of basic rules that governs<br />

how you write programs in that language. It is the lowest-level syntax of the language<br />

and specifies such things as what variable names look like, what characters are<br />

used for comments, and how program statements are separated from each other.<br />

Case Sensitivity<br />

The names of user-defined classes and functions, as well as built-in constructs and<br />

keywords such as echo, while, class, etc., are case-insensitive. Thus, these three lines<br />

are equivalent:<br />

echo("hello, world");<br />

ECHO("hello, world");<br />

EcHo("hello, world");<br />

Variables, on the other hand, are case-sensitive. That is, $name, $NAME, and $NaME are<br />

three different variables.<br />

Statements and Semicolons<br />

A statement is a collection of <strong>PHP</strong> code that does something. It can be as simple as<br />

a variable assignment or as complicated as a loop with multiple exit points. Here is<br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2002 O’Reilly & Associates, Inc. All rights reserved.<br />

17

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!