Appendix A. PHP for C Programmers

In this appendix, we assume that you have more C (or C++) programming experience than PHP experience and are looking to get up to speed in PHP quickly. First, we'll provide a quick overview of PHP from a C perspective; next, we'll break down the similarities and differences, and finally we'll point out which parts of the book you are likely to benefit from the most.

The simplest way to think of PHP is as interpreted C that you can embed in HTML documents. The language itself is a lot like C, except with untyped variables, a whole lot of web-specific libraries built in, and everything hooked up directly to your favorite web server. The syntax of statements and function definitions should be familiar, except that variables are always preceded by $, and functions do not require separate prototypes.

Similarities

In this section, we offer some notes (by no means exhaustive) on ways in which PHP can be expected to be C-like.

Syntax

Broadly speaking, PHP syntax is the same as in C: Code is blank-insensitive, statements are terminated with semicolons, function calls have the same structure (my_function(expression1, expression2)), and curly braces ({ and }) make statements into blocks. PHP supports C and C++ style comments (/* */ as well as //), and also Perl and shell-script-style (#) ones.

Operators

The assignment operators (=, +=, *=, and so on), the Boolean operators (&&, ||, !), the comparison operators (<, >, <=, >=, ==, !=), and the basic arithmetic operators ...

Get PHP6 and MySQL® 6 Bible now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.