8. Does this look familiar?
This is called functional programming
9. Functional Programming in PHP
• PHP supports first-class functions
• Both user-defined and built-in functions can be referenced by a variable and invoked
dynamically
• Functions can be passed as arguments to other functions and a function can return other
functions (a feature called higher-order functions)
• Recursion, a feature that allows a function to call itself, is supported by the language, but most
of the PHP code focus is on iteration.
• Anonymous functions (with support for closures) have been present since PHP 5.3 (2009).
• PHP 5.4 added the ability to bind closures to an object’s scope and also improved support for
callables such that they can be used interchangeably with anonymous functions in almost all
cases
10. Functional Programming in PHP
• The most common usage of higher-order functions is when
implementing a strategy pattern. The built-in array_filter() function
asks both for the input array (data) and a function (a strategy or a
callback) used as a filter function on each array item.
• AND... That's pretty much all uses cases in standard development
• But wait!!! It should be more use cases?!
11. How many times did you find yourself writing the
same generic code over and over?
13. How does it look?
• More simpler?
• More understandable?
• More foolproof?
• Less complex?
• jQuery/Underscore.js for PHP?
14. When I have some questions
• Why we are using principles like DRY, KISS but don't apply them?
• Why we constantly write test to cover the same generic code?
• Why we write complex code over and over?