3
© Rob Aley 2017
R. Aley, Pro Functional PHP Programming, DOI 10.1007/978-1-4842-2958-3_1
CHAPTER 1
Introduction
Functional programming isn’t something that is often associated with PHP. Yet for quite a while PHP has had
all the features necessary to create software using the functional paradigm. In this book, you’ll take a look
at what functional programming is, how to do it in PHP, and the different ways in which you can use it to
improve your PHP software.
Who Is This Book For?
This book isn’t an introduction to PHP itself; it assumes you have some basic (or, indeed, advanced)
experience in PHP scripting. You don’t need to be an expert to follow along; I’ll cover all the key concepts
in PHP you’ll need to know to be able to implement functional designs in your code and point you in the
direction of resources such as web sites and other books that you can use to learn or investigate any related
concepts that I don’t cover directly.
Absolute PHP beginners aside, this book is suitable for all programmers. Whether you have a pressing
need to learn functional programming (perhaps you’ve taken over a functional PHP code base) or you are
just interested in finding out what the “buzz” around functional programming is all about, there is something
in this book for you. There’s even likely to be something for those skeptical about creating software using the
functional programming paradigm. I think that most programmers will find useful lessons and code patterns
to take away from the functional programming style that will enhance their object-oriented or procedural
programming work. If all else fails, knowledge of functional programming looks good on your résumé!
What Is Functional Programming?
Functional programming is a declarative programming paradigm that abstracts code into
pure, immutable, side-effect-free functions, allowing the programmer to compose such
functions together to make programs that are easy to reason about.
That is my definition of functional programming. Ask five other functional programmers to define functional
programming and you’ll get four more answers (two just copied the same answer from Wikipedia). There’s
no “standard” definition; different people and different programming languages implement functional
programming elements differently. These differences are partly because of the practicalities of the language
in question and sometimes because of the target platforms, data, and usage scenarios, but often they come
down to what I call “programming religion”: a fixed, sometimes irrational, but often deeply held belief of
how a particular paradigm should be. Even within the small community of PHP functional programmers,
you won’t find an exact consensus. In PHP, functional programming is not a core concept, but even in
languages where it is (e.g., Lisp, Scala, etc.), there are many “related” understandings of what constitutes true
functional programming. While that may sound problematic, you’ll still “know it when you see it,” and when
it gets woolly around the edges, you can choose to define it in any way you see fit!