Functional Programming in PHP. From Basics to Real Projects
300 pages
English
PDF
4.5

Functional Programming in PHP. From Basics to Real Projects

Functional Programming in PHP. From Basics to Real Projects

Author:

Year:

Summary:

The book "Functional Programming in PHP" is a practical guide for PHP developers who want to go beyond the imperative style and master the powerful tools of the functional paradigm. The author, Alexey Kuznetsov, a Senior PHP Developer with 10 years of experience, shows how to apply functional programming (FP) concepts in real PHP projects, making code more predictable, testable, and easy to maintain.



The book starts with the basics: you will learn what function purity, side effects, and data immutability are. The author then systematically covers key topics:



  • Functions as First-Class Objects — working with anonymous functions, closures, and bound closures ($this, bindTo).
  • Composition and Currying — creating function chains, partial application of arguments, and building data processing pipelines.
  • Recursion and Tail Recursion — writing recursive algorithms without stack overflow (using trampoline).
  • Monads and Functors — practical application of Maybe, Either, IO, and Writer for safe error handling and side effects.
  • Lazy Evaluation — creating generators and infinite sequences with memory efficiency.
  • Testing Functional Code — how to write unit tests for pure functions and work with mocks.


A separate chapter is dedicated to integrating FP into popular frameworks (Laravel, Symfony): you will learn how to use functional approaches in Eloquent queries, collections, service providers, and middleware.



The book will be useful for:

  • Junior+ and Middle PHP developers looking to improve code quality;
  • team leads and architects seeking ways to reduce module coupling;
  • anyone who wants to learn functional programming in a specific language without switching to Haskell or Scala.


Basic knowledge of PHP (variables, loops, functions) is sufficient to study the material. All examples are provided with detailed comments and are available in a GitHub repository. After reading, you will be able to write more elegant, modular, and predictable code, as well as easily implement functional patterns in existing projects.

Recommendations