SlideShare a Scribd company logo
Functional Programming in PHP
A secret place behind OOP shadow
– Michael Feathers
“OO makes code understandable by encapsulating moving parts.
FP makes code understandable by minimizing moving parts.”
- Someone from internet
“...The less moving parts a machine has, the less likely it is going
to break down...”
So it means OOP is bad?
Not really...
So what we should do when?
We already use them together
Where??? How??
Does this look familiar?
Does this look familiar?
This is called functional programming
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
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?!
How many times did you find yourself writing the
same generic code over and over?
What do you think about this?
How does it look?
• More simpler?
• More understandable?
• More foolproof?
• Less complex?
• jQuery/Underscore.js for PHP?
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?
Thank you!

More Related Content

PPTX
How to Supercharge your PHP Web API
PDF
Metaprogramming Go
PPTX
Flask and Paramiko for Python VA
PDF
Migrate PHP E-Commerce Site to Go
PDF
Performance and Abstractions
PDF
Python to go
PDF
Why use Go for web development?
PDF
Fast Web Applications with Go
How to Supercharge your PHP Web API
Metaprogramming Go
Flask and Paramiko for Python VA
Migrate PHP E-Commerce Site to Go
Performance and Abstractions
Python to go
Why use Go for web development?
Fast Web Applications with Go

What's hot (16)

PPT
Ria Applications And PHP
PPTX
Proxying DBI with DBD::Gofer and App::Staticperl
PPTX
Automating JavaScript testing with Jasmine and Perl
PPTX
Developing Rich Internet Applications with Perl and JavaScript
PDF
SGCE 2015 REST APIs
PDF
Riak at Posterous
PPT
Sylius ecommerce solution for Symfony2 (WebCamp Ljubljana)
PDF
Making CLI app in ruby
PDF
RubyConf Taiwan 2016 - Large scale Rails applications
PDF
Introduction to Django (GDays 2014)
PDF
Stackato v6
PPTX
Api crash
PDF
GitHub as a Landing Page
PDF
[Start] Playing
PDF
Automating everything with Microsoft Flow
PDF
Approaching APIs
Ria Applications And PHP
Proxying DBI with DBD::Gofer and App::Staticperl
Automating JavaScript testing with Jasmine and Perl
Developing Rich Internet Applications with Perl and JavaScript
SGCE 2015 REST APIs
Riak at Posterous
Sylius ecommerce solution for Symfony2 (WebCamp Ljubljana)
Making CLI app in ruby
RubyConf Taiwan 2016 - Large scale Rails applications
Introduction to Django (GDays 2014)
Stackato v6
Api crash
GitHub as a Landing Page
[Start] Playing
Automating everything with Microsoft Flow
Approaching APIs
Ad

Similar to Functional Programming in PHP (20)

PPTX
Introduction to Functional Programming
PPTX
Chapter1_ObjectOrientedProgramming.pptx
PDF
PDF
OOPs-Interview-Questions.pdf
PPT
PHP - Introduction to PHP Fundamentals
PPTX
Learn PHP Lacture1
PPTX
Why functional programming in C# & F#
PPTX
Oop.pptx
PPTX
Introduction to PHP and MySql basics.pptx
PDF
Exploring PHP's Built-in Functions
PPTX
Object Oriented programming - Introduction
PPTX
Php internal architecture
PDF
Top 100 PHP Questions and Answers
PPT
Oops in PHP By Nyros Developer
PPTX
php basic part one
PPTX
PHP Internals
PDF
Beginning PHP
Introduction to Functional Programming
Chapter1_ObjectOrientedProgramming.pptx
OOPs-Interview-Questions.pdf
PHP - Introduction to PHP Fundamentals
Learn PHP Lacture1
Why functional programming in C# & F#
Oop.pptx
Introduction to PHP and MySql basics.pptx
Exploring PHP's Built-in Functions
Object Oriented programming - Introduction
Php internal architecture
Top 100 PHP Questions and Answers
Oops in PHP By Nyros Developer
php basic part one
PHP Internals
Beginning PHP
Ad

Recently uploaded (20)

PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Electronic commerce courselecture one. Pdf
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Encapsulation theory and applications.pdf
PDF
Modernizing your data center with Dell and AMD
Per capita expenditure prediction using model stacking based on satellite ima...
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
“AI and Expert System Decision Support & Business Intelligence Systems”
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Unlocking AI with Model Context Protocol (MCP)
Diabetes mellitus diagnosis method based random forest with bat algorithm
The Rise and Fall of 3GPP – Time for a Sabbatical?
Dropbox Q2 2025 Financial Results & Investor Presentation
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
The AUB Centre for AI in Media Proposal.docx
Chapter 3 Spatial Domain Image Processing.pdf
Review of recent advances in non-invasive hemoglobin estimation
Electronic commerce courselecture one. Pdf
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Encapsulation theory and applications.pdf
Modernizing your data center with Dell and AMD

Functional Programming in PHP

  • 1. Functional Programming in PHP A secret place behind OOP shadow
  • 2. – Michael Feathers “OO makes code understandable by encapsulating moving parts. FP makes code understandable by minimizing moving parts.”
  • 3. - Someone from internet “...The less moving parts a machine has, the less likely it is going to break down...”
  • 4. So it means OOP is bad?
  • 5. Not really... So what we should do when?
  • 6. We already use them together Where??? How??
  • 7. Does this look familiar?
  • 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?
  • 12. What do you think about this?
  • 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?