O'Reilly logo

Functional PHP by Gilles Crettenand

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Laravel

As we have already discussed, the collection API from Laravel is a good example of an immutable data structure with nice functional methods on top of it. The database layer returning instances of the Collection class really helps with streamlining its use.

However, the Facade pattern proposed by the framework is a no-go if you want to keep your functions pure. As soon as you use a façade, you end up using an external dependency that is not declared in your function signature.

Whatever your take on this pattern is, if you want to write referentially transparent code, you have to get rid of them. Luckily, Laravel provides helper functions for most common tasks and a way to access the container that is baking the facade. As we will see, it ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required