Pure functions

Let's say you have the function signature function getCurrentTvProgram (Channel $channel). Without any indication of the purity of the function, you have no idea of the complexity that may be hidden behind such a function.

You will probably get the program that is actually playing on the given channel. What you don't know is whether the function checked if you are logged into the system. Maybe there's some kind of database update for analytic purposes. Maybe the function will return an exception because the log file is in a read-only state. You cannot know for sure, and all of those are side causes or side effects.

Regarding all the complexity associated with those hidden dependencies, you are faced with three options:

  • Dive deep down ...

Get Functional PHP now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.