Getting functional with PHP
I’m in love with JavaScript functional programming and being also a PHP developer, I tried to mix theses two things together. Let’s see what I get.
First: I’m not talking about functional stuff like maps, filters and reducers, I’m talking about true funcional programming, at least what I understand about it. And what is that?
If you know my Meteor-Redux repository, you know that a like much more principles over implementations and the main motivation for functional programming is immutability.
Immutability has been a keyword around JavaScript community, Facebook does like it and in fact, it’s a great pattern. I personally haven’t see much about immutability and PHP, but the DateTimeImmutable class was for sure a great addition.
PHP is about the Web, so we need to understand Web and FP first. Web is a client-server architecture. Client sends a request and server sends a response, REST specification already point us to do this a stateless communication. Client request as current state and server response as functional evaluation is a great start, we can implement PHP pure-functions receiving a Request and returning a Response.
Less talk, more code.