Functional PHP

Uncover the secrets of functional programming with PHP to ensure your applications are as great as they can be
Preview in Mapt

Functional PHP

Gilles Crettenand

Uncover the secrets of functional programming with PHP to ensure your applications are as great as they can be
Mapt Subscription
FREE
$29.99/m after trial
eBook
$10.00
RRP $35.99
Save 72%
Print + eBook
$44.99
RRP $44.99
What do I get with a Mapt Pro subscription?
  • Unlimited access to all Packt’s 5,000+ eBooks and Videos
  • Early Access content, Progress Tracking, and Assessments
  • 1 Free eBook or Video to download and keep every month after trial
What do I get with an eBook?
  • Download this book in EPUB, PDF, MOBI formats
  • DRM FREE - read and interact with your content when you want, where you want, and how you want
  • Access this title in the Mapt reader
What do I get with Print & eBook?
  • Get a paperback copy of the book delivered to you
  • Download this book in EPUB, PDF, MOBI formats
  • DRM FREE - read and interact with your content when you want, where you want, and how you want
  • Access this title in the Mapt reader
What do I get with a Video?
  • Download this Video course in MP4 format
  • DRM FREE - read and interact with your content when you want, where you want, and how you want
  • Access this title in the Mapt reader
$0.00
$10.00
$44.99
$29.99 p/m after trial
RRP $35.99
RRP $44.99
Subscription
eBook
Print + eBook
Start 30 Day Trial

Frequently bought together


Functional PHP Book Cover
Functional PHP
$ 35.99
$ 10.00
Object-oriented and Functional Programming with Java 8 [Integrated Course] Book Cover
Object-oriented and Functional Programming with Java 8 [Integrated Course]
$ 124.99
$ 10.00
Buy 2 for $20.00
Save $140.98
Add to Cart

Book Details

ISBN 139781785880322
Paperback342 pages

Book Description

A functional approach encourages code reuse, greatly simplifies testing, and results in code that is concise and easy to understand. This book will demonstrate how PHP can also be used as a functional language, letting you learn about various function techniques to write maintainable and readable code.

After a quick introduction to functional programming, we will dive right in with code examples so you can get the most of what you’ve just learned. We will go further with monads, memoization, and property-based testing. You will learn how to make use of modularity of function while writing functional PHP code.

Through the tips and best practices in this book, you’ll be able to do more with less code and reduce bugs in your applications. Not only will you be able to boost your performance, but you will also find out how to eliminate common loop problems. By the end of the book, you will know a wide variety of new techniques that you can use on any new or legacy codebase.

Table of Contents

Chapter 1: Functions as First Class Citizens in PHP
Before we begin
Functions and methods
PHP 7 scalar type hints
Anonymous functions
Closures
Using objects as functions
The Closure class
Higher-order functions
What is a callable?
Summary
Chapter 2: Pure Functions, Referential Transparency, and Immutability
Two sets of input and output
Pure functions
Immutability
Referential transparency
PHP in all that?
Summary
Chapter 3: Functional Basis in PHP
General advice
The map function
The filter function
The fold or reduce function
Convolution or zip
Recursion
Exceptions
Alternatives to exceptions
The Option/Maybe and Either types
Libraries
Summary
Chapter 4: Composing Functions
Composing functions
Partial application
Currying
Parameter order matters a lot!
Using composition to solve real issues
Summary
Chapter 5: Functors, Applicatives, and Monads
Functors
Applicative functors
Monoids
Monads
Further reading
Summary
Chapter 6: Real-Life Monads
Monadic helper methods
Maybe and Either monads
List monad
Writer monad
Reader monad
State monad
IO monad
Summary
Chapter 7: Functional Techniques and Topics
Type systems
Point-free style
Using const for functions
Recursion, stack overflows, and trampolines
Pattern matching
Type classes
Algebraic structures and category theory
Monad transformers
Lenses
Summary
Chapter 8: Testing
Testing vocabulary
Testing pure functions
Speeding up using parallelization
Property-based testing
Summary
Chapter 9: Performance Efficiency
Performance impact
Memoization
Parallelization of computation
Summary
Chapter 10: PHP Frameworks and FP
Symfony
Laravel
Drupal
WordPress
Summary
Chapter 11: Designing a Functional Application
Architecture of a purely functional application
From Functional Reactive Animation to Functional Reactive Programming
ReactiveX primer
RxPHP
Summary
Chapter 12: What Are We Talking about When We Talk about Functional Programming
What is functional programming all about?
Why is functional programming the future of software development?
A quick history of the functional world
Functional jargon

What You Will Learn

  • Declare functions/callables and find out how to manipulate and call them
  • Write pure functions to get more robust code that can be easily tested
  • Learn to compose function using various techniques
  • Use a functional approach to find readable solutions to common issues
  • Utilize performance optimization techniques such as laziness, memorization, and parallelization
  • Build the business logic of applications with the functional paradigm
  • Test functional code and know how to speed up test runs using parallel testing
  • Understand the impact and limitation of functional programming in PHP

Authors

Table of Contents

Chapter 1: Functions as First Class Citizens in PHP
Before we begin
Functions and methods
PHP 7 scalar type hints
Anonymous functions
Closures
Using objects as functions
The Closure class
Higher-order functions
What is a callable?
Summary
Chapter 2: Pure Functions, Referential Transparency, and Immutability
Two sets of input and output
Pure functions
Immutability
Referential transparency
PHP in all that?
Summary
Chapter 3: Functional Basis in PHP
General advice
The map function
The filter function
The fold or reduce function
Convolution or zip
Recursion
Exceptions
Alternatives to exceptions
The Option/Maybe and Either types
Libraries
Summary
Chapter 4: Composing Functions
Composing functions
Partial application
Currying
Parameter order matters a lot!
Using composition to solve real issues
Summary
Chapter 5: Functors, Applicatives, and Monads
Functors
Applicative functors
Monoids
Monads
Further reading
Summary
Chapter 6: Real-Life Monads
Monadic helper methods
Maybe and Either monads
List monad
Writer monad
Reader monad
State monad
IO monad
Summary
Chapter 7: Functional Techniques and Topics
Type systems
Point-free style
Using const for functions
Recursion, stack overflows, and trampolines
Pattern matching
Type classes
Algebraic structures and category theory
Monad transformers
Lenses
Summary
Chapter 8: Testing
Testing vocabulary
Testing pure functions
Speeding up using parallelization
Property-based testing
Summary
Chapter 9: Performance Efficiency
Performance impact
Memoization
Parallelization of computation
Summary
Chapter 10: PHP Frameworks and FP
Symfony
Laravel
Drupal
WordPress
Summary
Chapter 11: Designing a Functional Application
Architecture of a purely functional application
From Functional Reactive Animation to Functional Reactive Programming
ReactiveX primer
RxPHP
Summary
Chapter 12: What Are We Talking about When We Talk about Functional Programming
What is functional programming all about?
Why is functional programming the future of software development?
A quick history of the functional world
Functional jargon

Book Details

ISBN 139781785880322
Paperback342 pages
Read More

Read More Reviews

Recommended for You

PHP 7 Data Structures and Algorithms Book Cover
PHP 7 Data Structures and Algorithms
$ 35.99
$ 10.00
PHP Microservices Book Cover
PHP Microservices
$ 35.99
$ 10.00
Mastering PHP Design Patterns Book Cover
Mastering PHP Design Patterns
$ 35.99
$ 10.00
PHP 7 Programming Cookbook Book Cover
PHP 7 Programming Cookbook
$ 39.99
$ 10.00
PHP 7: Real World Application Development Book Cover
PHP 7: Real World Application Development
$ 69.99
$ 10.00
ReactJS by Example - Building Modern Web Applications with React Book Cover
ReactJS by Example - Building Modern Web Applications with React
$ 35.99
$ 10.00