PHP: The Right Way
144 pages
English
PDF
4.5

PHP: The Right Way

PHP: The Right Way

Author:

Year:

Summary:

Introduction

The book "PHP: The Right Way" by Josh Lockhart is not just another textbook on the language, but a living, constantly updated guide to the best practices, standards, and tools of the PHP ecosystem. First published in 2013, it quickly became a desktop book for thousands of developers worldwide. The 2021 edition, at 144 pages, is a compact but extremely rich reference that covers all key aspects of modern PHP development: from syntax basics to advanced topics such as dependency injection, testing, and security.

The book is available in open access on the official project website, as well as in print. Its uniqueness lies in the fact that it is not tied to a specific PHP version — the author constantly updates the material, so the reader receives only current recommendations that correspond to the latest stable releases (including PHP 8.x).

What is this book about?

"PHP: The Right Way" is a collection of proven solutions and architectural approaches that will help you write clean, maintainable, and secure code. The book does not teach the basics of syntax (it assumes the reader is already familiar with PHP), but focuses on how to properly organize your workflow, choose tools, and avoid common mistakes.

The structure of the book is logical and intuitive. It is divided into several major sections:

  • Basics — environment setup, editor selection, working with Composer, PSR-4 autoloading.
  • Coding Standards — PSR-1, PSR-12, naming classes, methods, and variables.
  • Working with Data — PDO, MySQLi, input filtering, protection against SQL injection.
  • Object-Oriented Programming — SOLID, design patterns, dependency injection.
  • Testing — PHPUnit, Mockery, TDD/BDD.
  • Security — XSS, CSRF, password hashing, working with sessions.
  • Tools and Libraries — frameworks (Laravel, Symfony), template systems (Twig), logging (Monolog).

Who is this book for?

The book is intended for intermediate and advanced PHP developers who already have coding experience but want to systematize their knowledge, learn about modern standards, and get rid of outdated practices. It will also be useful for those transitioning from other languages (e.g., Python or Java) and wanting to quickly master "proper" PHP.

For beginners just starting to learn PHP, the book may seem difficult due to the abundance of terms and references to tools, but after mastering the basic syntax, it will be an excellent second step.

What will the reader learn?

After reading, you will be able to:

  • Set up a modern environment for PHP development (Docker, PHPStorm, Xdebug).
  • Use Composer for dependency management and class autoloading.
  • Write code that complies with PSR-1, PSR-4, and PSR-12 standards.
  • Work with databases via PDO, avoiding vulnerabilities.
  • Apply SOLID principles and design patterns (Factory, Singleton, Repository).
  • Cover code with unit tests using PHPUnit and Mockery.
  • Protect applications from XSS, CSRF, SQL injection, and other attacks.
  • Choose the right framework (Laravel, Symfony) and libraries (Twig, Monolog).
  • Optimize performance and use caching (APCu, Redis).

Strengths of the book

The main advantage of "PHP: The Right Way" is its relevance. Unlike many books that become outdated after a year or two, this guide lives on the internet and is updated by the community. The 2021 print edition is a snapshot of best practices at the time of release, but even now it remains 90% relevant.

The second strong point is its conciseness.

Recommendations