Front cover of PHP the TPRM Way

The book

PHP the TPRM Way

A Hands-On Beginner’s Guide to Modern PHP 8+

PHP is a general-purpose programming language, and it plays a particularly strong role on the server side of the web. It also runs from the command line, which makes it a good language for learning core programming ideas before you add browser requests, forms, sessions, and databases.

The progression here is deliberate. Values and expressions come first, then decisions, loops, functions, text, collections, files, defensive programming, classes, and complete projects. I introduce the PHP-specific web concepts only once the programming fundamentals are comfortable for you.

The examples target modern PHP 8.x, and I keep to durable language features rather than to a framework. Frameworks have their value later on. Learning plain PHP first makes their conventions far easier to understand and to evaluate.

  • Printed in the book as tprmway.com/php. That address will keep working.
  • 200 pages, paperback, 6 by 9 inches.

Start here

Three things have to be in place before the first program runs. These notes are the current version of the Before You Start section in the book.

Read the setup notes — PHP the TPRM Way

Chapter companions

One page per chapter: what the chapter teaches, every program in it ready to type, and the prediction that goes with each one. The explanations stay in the book.

  1. Chapter 1 Your First PHP Programs and Reading ErrorsRun PHP on purpose rather than by habit. Learn how the interpreter works through your file, and read the errors it gives you as evidence.
  2. Chapter 2 Variables, Types, Input, and OutputA variable is a name for a value. Learn to see the type behind that value, take input from the terminal, and convert it on purpose.
  3. Chapter 3 Numbers, Operators, and ExpressionsArithmetic looks like the simplest part of a language. Learn the operators, the precedence rules, and the places where decimals are not quite what they appear to be.
  4. Chapter 4 Decisions and Boolean LogicA program becomes useful the moment it can choose. Write comparisons that say exactly what you mean, and put the conditions in an order that holds up.
  5. Chapter 5 Loops and RepetitionRepetition is where a small mistake gets multiplied. Give every loop clear boundaries, state you can trace by hand, and a definite way out.
  6. Chapter 6 Functions and Program StructureA function is a name attached to a piece of behavior. Give it explicit inputs, one clear result, and a scope of its own.
  7. Chapter 7 Strings and Text ProcessingMost of what a program handles is text. Learn to measure it, split it, search it, normalize it, and put it on a page safely.
  8. Chapter 8 Arrays and CollectionsAn array holds many values under one name. Walk it safely, search it correctly, and know which operations change it and which hand you a copy.
  9. Chapter 9 Associative Arrays and Structured DataReal data arrives as records with named fields. Model one record, handle a field that is missing, and process a whole collection of them.
  10. Chapter 10 Web Forms, Requests, and ValidationPHP starts answering requests here instead of a command line. The convenience of a superglobal is not the same thing as trust.
  11. Chapter 11 Files, JSON, and SessionsData that outlives one run has to be written somewhere. Learn files, JSON and sessions, and learn where each of them stops being the right answer.
  12. Chapter 12 Building Safer, Better PHP ProgramsPrograms fail, and users are not always friendly. Handle failure deliberately, and protect each boundary with the control that fits it.
  13. Chapter 13 Classes and ObjectsSometimes data and the rules about that data belong together. A class is how you bundle them, and how you make an invalid object impossible.
  14. Chapter 14 Four Complete Beginner ProjectsFour complete applications, each one built a milestone at a time. They combine the language fundamentals with PHP boundaries that grow steadily more realistic.

Free downloads

  • PHP Syntax Cheat Sheet

    Core syntax and operators on a compact printable reference: program basics, variables and types, conversion, strings, arithmetic, comparison, decisions, match, loops, functions, string handling, indexed arrays, array transformation, and associative arrays.

    Cheat sheet · PDF · 2 pages · 58 KB · Version 2026-09-07

  • JSON, Sessions, PDO, and Exceptions Quick Reference

    The four boundaries where a PHP program meets stored data, on one sheet: JSON encoding and decoding, small-file persistence, session handling, PDO connections and prepared statements, reading rows, exceptions, the errors you meet, and the password API.

    Cheat sheet · PDF · 2 pages · 52 KB · Version 2026-09-07

  • Request Validation and HTML Output Checklist

    One printable page to work down before a form page meets a real visitor: reading the request, validating meaning, trust boundaries, escaping at the output boundary, the states a page has to have, and the inputs to test it with.

    Checklist · PDF · 1 page · 36 KB · Version 2026-09-07

  • PHP Debugging Checklist

    One printable page to work through before you change a line: what to check before you run, how to read a PHP message, what to do when the program runs and the answer is wrong, and what to verify before calling it finished.

    Checklist · PDF · 1 page · 36 KB · Version 2026-09-07

  • Common PHP Errors and Warnings

    Forty real PHP messages in roughly the order a beginner meets them, each with what it means, what to check first, and the smallest program that produces it.

    Common errors · PDF · 6 pages · 80 KB · Version 2026-09-07

  • 50 Extra Practice Questions

    Three or four questions per chapter across all fourteen chapters, weighted toward tracing, debugging, and building from a blank file, with answers complete enough to check yourself against.

    Practice questions · PDF · 43 pages · 187 KB · Version 2026-09-07

  • Practice Test Pack

    Thirty mixed questions covering the whole book in four parts: predict the output, find and fix the defect, short answer, and write the code. Answers are included.

    Practice test · PDF · 23 pages · 126 KB · Version 2026-09-07

  • Project Starter Files

    Clean files for the four Chapter 14 projects, with the function names the chapter uses, TODO comments keyed to the build milestones, a README carrying the requirements and acceptance tests, JSON fixture data, a server-side catalog, and an empty SQL schema. They run as they stand; they are not solutions.

    Starter files · ZIP · 16 files · 24 KB · Version 2026-09-07

Open the downloads page

More for this book

  • Quick reference The syntax you will look up most often, on one page.
  • Corrections What is wrong in the printed book, and what it should say.