Many languages have embraced Functional Programming paradigms to augment the tools available for programmers to solve problems. It facilitates writing code which is easier to understand, easier to test, and able to take advantage of parallelization. Functional Programming is a good fit for building modern, scalable solutions. Can you use functional programming in PHP?
PHP introduced anonymous function and closures in 5.3, providing a more succinct way to tackle common problems. More recent releases have added generators and variadics which can help write more concise, functional code. However, making the mental leap from programming in the more common imperative style requires understanding how and when to best use lambdas, closures, recursion, and more. It also requires learning to think of data in terms of collections for mapping, reducing, flattening, and filtering.
Functional Programming in PHP will show you how to leverage these new language features by understanding functional programming principles. With over twice as much content as its predecessor, this second edition expands upon its predecessor with updated code examples and coverage of advances in PHP 7 and Hack. Each chapter provides plenty of examples to illustrate each concept as it’s introduced and to show how to implement it with PHP. You’ll learn how to use map/reduce, currying, composition, and more. Finally, the book reviews the available external libraries and looks at new language features proposed for extending PHP’s functional programming capabilities.
Read a sample excerpt from the book
The sample includes the Table of Contents and Index.
Functional Programming in PHP Contents
This book covers the following topics in depth:
- History and Benefits of Functional Programming
- Language features including Types, Functions, Namespacing
- Using Recursion, Map, Reduce, and Filtering.
- How to use Memoization and Generators
- Helpful 3rd Party Libraries
- Functional Programming in HHVM’s Hack
- Functional Patterns including Composition, Partial Functions, and Pipelines
- Explanation of Pattern Matching, Functors, Applicatives, Monads, and Currying
- Implementation Examples
- Event Drive Programming
What others are saying
This @phparch book is good for general functional programming concepts: https://t.co/6DybvzmrXn
— assertchris (@assertchris) March 28, 2017
About the Author
Simon Holywell is a Senior Software Engineer at Aurion in Brisbane, Australia (http://aurion.com) and is passionate about web application development and motorcycles. His first public project was written with PHP 3, and since then, he has worked with every version of PHP and dabbled in Python, Scala, C, JavaScript, and more. He is also the author of of SQLStyle.guide and the ssdeep extensions for PHP’s PECL, Facebook’s HipHop Virtual Machine (HHVM), and MySQL.
See his blog and follow him on Twitter: @Treffynnon