Front cover of PHP Done The Correct Way, 2nd Edition, by Ian Croasdell, with a PHP 8.5 badge
2nd Edition · PHP AIR

PHP Done The Correct Way

A practical guide to modern PHP, maintainable systems, and production-ready habits

  • Written for PHP 8.5
  • By Ian Croasdell
  • 24 chapters in 3 parts
  • PDF

Modern PHP, built the way working systems need it.

£29.00 · PDF download, sent straight away

Secure payment by PayPal (PayPal account or card). We never see your card details. You get a download link on the next page and by email: 5 downloads, valid for 7 days.

About the book

This book teaches PHP 8.5 as it is used on real, maintained websites: strict types, tested code, prepared statements, escaped output, safe passwords and sessions, and deployments you can repeat and roll back.

Across 24 chapters you build one small application for a fictional handyman business, Northstar Repairs, with enquiry forms, a database, logins, invoices with VAT in integer pence, background jobs and a production server. The example programs are run on PHP 8.5 every time the book is built, and the output printed in the book is the output they produced.

It assumes you can use a text editor and a terminal, and have built a web page before. It does not assume you know PHP, and it does not teach the old ways first and correct them later.

Inside

  • Types, functions, arrays, dates and money without bad habits
  • Forms, sessions, PDO and the security basics, done properly
  • Testing, Composer, APIs, webhooks and background jobs
  • Performance, deployment, backups and modernising old code
  • A production checklist you can use on your own projects

Who it is for

New PHP developers

Who want to learn the language properly the first time.

Developers returning to PHP

After years away, who need to know what has changed since PHP 5 and 7.

Freelancers and small agencies

Building and running sites for UK businesses, who need the production, legal and business chapters as much as the code.

Contents

Read Parts 1 and 2 in order; each chapter builds on the one before. Part 3 chapters can be read in any order once you have finished Chapter 16.

Part 1: Foundations

Set up properly, learn the language without bad habits, and build your first small programs.

  1. 1What Correct PHP Means In 2026The habits that separate code that works today from code that keeps working
  2. 2Setting Up A PHP WorkspaceInstall PHP 8.5, configure it for development, and work the same way on every machine
  3. 3PHP Syntax Without Bad HabitsStatements, strings, operators, decisions and loops, written the way professionals write them
  4. 4Types, Values, Comparisons, And StrictnessKnow what every value is, and make PHP check it for you
  5. 5Functions, Files, And Small ProgramsName your logic, split it into files, read and write data safely, and build a proper command-line tool
  6. 6Arrays, Strings, Dates, And MoneyThe everyday data of a business, handled so it is right to the character, the hour and the penny
  7. 7Forms, Requests, Responses, And SessionsTake an enquiry from a stranger's browser, check it, store it, and answer properly
  8. 8Templates And Page StructureSeparate HTML from logic, build every page from one layout, and escape by default

Part 2: Building Applications

Objects, Composer, databases with PDO, validation and escaping, passwords and logins, errors and logs, and testing, ending with a small but complete application.

  1. 9Object-Oriented PHP That Stays UnderstandableClasses, enums and value objects that make the rules of the business impossible to break by accident
  2. 10Composer, Autoloading, And Package DisciplineLoad your own classes automatically, and use other people's code without inheriting their problems
  3. 11Databases With PDO And Prepared StatementsStore business data in SQLite with migrations, prepared statements, transactions and a repository
  4. 12Validation, Escaping, And Security BasicsOne clear boundary between untrusted input and trusted code, and the defences that sit on it
  5. 13Passwords, Login Systems, And User DataStore passwords the only correct way, and build login, throttling and resets around them
  6. 14Errors, Exceptions, Logs, And DebuggingFail loudly to yourself and calmly to your visitors, and leave a trail you can follow
  7. 15Testing PHP Before It BreaksFast, honest tests with PHPUnit 12 that let you change code without fear
  8. 16Building A Small PHP ApplicationA complete, working Northstar site with routing, controllers, a database, login and templates

Part 3: Running PHP In The Real World

What happens after the code works, ending with every check in the book gathered into one production checklist.

  1. 17APIs, Webhooks, And External ServicesJSON that fails loudly, APIs that answer honestly, clients that retry safely, and webhooks you can trust
  2. 18Background Jobs, CLI Scripts, And AutomationQueues, workers, cron and systemd: doing slow work reliably, once, without making anyone wait
  3. 19Performance, Caching, And OPcacheMeasure first, then remove the work that does not need doing
  4. 20Deployment, Backups, And MaintenanceGoing live on a real server, deploying without downtime, and backups you have actually restored
  5. 21Working With Frameworks Without Losing The PlotWhat Laravel and Symfony do for you, how they do it, and how to stay in charge of your own application
  6. 22Modernising Old PHP CodeBringing a working but dated codebase up to PHP 8.5, safely, one tested step at a time
  7. 23PHP For Real BusinessesPersonal data, invoices, VAT, exports, accessibility and handover: the rules that are not about code
  8. 24The PHP AIR Production ChecklistEvery check in this book in one place, and a script that runs the ones a computer can check

Back matter

Appendix A: PHP 8.0 To 8.5 At A Glance · Glossary · Further Reading · About The Author

The code

  • Every listing was run on PHP 8.5 when the book was built, and the output printed beneath it is the real output of that run.
  • Every PHP file starts with declare(strict_types=1);, except a few deliberately old files in Chapter 22.
  • Money is held as integer pence and turned into pounds only for display.
  • Passwords are never trimmed, sanitised or altered: they are hashed exactly as typed with password_hash() and checked with password_verify().
  • Each chapter ends with common mistakes, exercises, a short checklist and sources: the pages on php.net, the PHP RFCs and other public references it relies on.

What you need

  • PHP 8.5 with the pdo_sqlite, mbstring, intl and sodium extensions (Chapter 2 shows how to install it on Windows, macOS and Linux)
  • Composer 2
  • A code editor with PHP support
  • SQLite, which needs no server, for the database chapters
  • For Part 3, a Linux server or virtual machine is helpful but not required
Ian Croasdell
About the author

Ian Croasdell

Ian Croasdell is a UK-based developer and problem-solver, and the founder of PHP AIR, which builds clean, lightweight PHP websites, booking and enquiry systems, and business-trained AI chat assistants for small businesses. His background is in electronics repair, networking, automation and web development. Before concentrating on web systems, he spent years repairing equipment, troubleshooting complex faults and creating practical solutions for real-world problems.

Alongside PHP AIR he runs Handyman Plus Van, a one-person handyman service that has been serving Swindon since 2016. Running the business gives him first-hand experience of enquiries, bookings, admin and customer questions.

PHP AIR built the Handyman Plus Van website, with its booking flow and business-trained AI chat assistant, and the website for Fabian Interiors. His own projects on GitHub include bbPress-Report-Abuse, a WordPress plugin written in PHP, and Hu-Mind, an offline-first AI research prototype with evidence, consensus and human action gates.

He does not believe in clever code for its own sake: he builds clear, durable systems that businesses can rely on.

PHP Done The Correct Way · £29 PDF

Corrections, questions and suggestions for the next edition are welcome at hello@phpair.co.uk.