SlideShare ist ein Scribd-Unternehmen logo
1 von 15
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!

Weitere ähnliche Inhalte

Was ist angesagt?

Proxying DBI with DBD::Gofer and App::Staticperl
Proxying DBI with DBD::Gofer and App::StaticperlProxying DBI with DBD::Gofer and App::Staticperl
Proxying DBI with DBD::Gofer and App::Staticperl
nohuhu
 
Automating JavaScript testing with Jasmine and Perl
Automating JavaScript testing with Jasmine and PerlAutomating JavaScript testing with Jasmine and Perl
Automating JavaScript testing with Jasmine and Perl
nohuhu
 
Developing Rich Internet Applications with Perl and JavaScript
Developing Rich Internet Applications with Perl and JavaScriptDeveloping Rich Internet Applications with Perl and JavaScript
Developing Rich Internet Applications with Perl and JavaScript
nohuhu
 
Introduction to Django (GDays 2014)
Introduction to Django (GDays 2014) Introduction to Django (GDays 2014)
Introduction to Django (GDays 2014)
Edem Kumodzi
 

Was ist angesagt? (16)

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

Ähnlich wie Functional Programming in PHP

Learn PHP Lacture1
Learn PHP Lacture1Learn PHP Lacture1
Learn PHP Lacture1
ADARSH BHATT
 
Top 100 PHP Questions and Answers
Top 100 PHP Questions and AnswersTop 100 PHP Questions and Answers
Top 100 PHP Questions and Answers
iimjobs and hirist
 

Ähnlich wie Functional Programming in PHP (20)

Introduction to Functional Programming
Introduction to Functional ProgrammingIntroduction to Functional Programming
Introduction to Functional Programming
 
Chapter1_ObjectOrientedProgramming.pptx
Chapter1_ObjectOrientedProgramming.pptxChapter1_ObjectOrientedProgramming.pptx
Chapter1_ObjectOrientedProgramming.pptx
 
OOPs-Interview-Questions.pdf
OOPs-Interview-Questions.pdfOOPs-Interview-Questions.pdf
OOPs-Interview-Questions.pdf
 
Oop's
Oop'sOop's
Oop's
 
PHP - Introduction to PHP Fundamentals
PHP -  Introduction to PHP FundamentalsPHP -  Introduction to PHP Fundamentals
PHP - Introduction to PHP Fundamentals
 
Learn PHP Lacture1
Learn PHP Lacture1Learn PHP Lacture1
Learn PHP Lacture1
 
Why functional programming in C# & F#
Why functional programming in C# & F#Why functional programming in C# & F#
Why functional programming in C# & F#
 
Oop.pptx
Oop.pptxOop.pptx
Oop.pptx
 
Exploring PHP's Built-in Functions
Exploring PHP's Built-in FunctionsExploring PHP's Built-in Functions
Exploring PHP's Built-in Functions
 
Php
PhpPhp
Php
 
Php
PhpPhp
Php
 
Php
PhpPhp
Php
 
Object Oriented programming - Introduction
Object Oriented programming - IntroductionObject Oriented programming - Introduction
Object Oriented programming - Introduction
 
Php internal architecture
Php internal architecturePhp internal architecture
Php internal architecture
 
Top 100 PHP Questions and Answers
Top 100 PHP Questions and AnswersTop 100 PHP Questions and Answers
Top 100 PHP Questions and Answers
 
Oops in PHP By Nyros Developer
Oops in PHP By Nyros DeveloperOops in PHP By Nyros Developer
Oops in PHP By Nyros Developer
 
php basic part one
php basic part onephp basic part one
php basic part one
 
PHP Internals
PHP InternalsPHP Internals
PHP Internals
 
Beginning PHP
Beginning PHPBeginning PHP
Beginning PHP
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 

Kürzlich hochgeladen

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Kürzlich hochgeladen (20)

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 

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?