SlideShare a Scribd company logo
PHP Mega Meetup, Sep, 2020, Anti patterns in php
Anti-patterns in php
Sep, 2020
Ahmed
Who is this guy
?
● Ahmed
● In the industry for about 9 years, I
worked as SRE, PM but mostly
Software engineer.
● I love all languages but PHP a little
bit more.
● Opensource advocate.
PHP Mega Meetup, Sep, 2020, Anti patterns in php
● Low cost, high-risk actions.
● Composer.
● Inheritance.
● Standardization
● Testing
● Logging
● Observability
● Continuous integration
● Containers
Anti-patterns in php
Low cost, high-risk actions
Anti-patterns in php
PHP is easy and makes everything sounds that everything will work correctly on
it's own.
Low cost, high-risk actions
Low cost, high-risk actions
After you deploy your app to production, always expect:
- To be asked to extend certain feature.
- Add new feature.
- To get bug reports and be able to understand it and fix it.
Low cost, high-risk actions
Every technical action makes it easier or harder to :
- Quickly modify the code base and make the PMs/CXOs happy.
- Make you and your teammates happy when they fix a bug.
So, while coding ...
Anti-patterns in php
Composer
Please, please, do not use the Death Star,
The Death Star is a bomb waiting to explode in the
team face
always use version constraints.
Composer
Please do not edit composer files manually at all
Please, please, use composer commands, they are super easy.
“The new composer package is working locally but not working on the server”
Extending classes
● Each parent should not many children. It becomes hard to change the
parent even with 100% testing coverage.
● System design is thrown out of the window with the overuse of inheritance,
easy solutions like visibility change for the sake of easiness over-power the
design and leads to GOD-classes eventually very easily.
● This is the exact recipe to create a bad monolith
Extending classes
Inheritance is not the only way
to extend a functionality.
Also taxes are high
on inheritance these days.
Extending classes
Inheritance is not the only way
to extend a functionality,
for example composition.
https://en.wikipedia.org/wiki/Composition_over_inheritance
Fun Fun Function: Composition over Inheritance
Depending on the environment
Avoid depending on the environment, for example
Instead: you can use environment variables
“I can not test it, It works only on PROD”
Standardization
https://xkcd.com/927/
Standardization
Standardization
Standardization
API with no OpenAPI/Swagger specs is not an API.
But It’s a good way to waste time and frustration everyone.
https://github.com/zircote/swagger-php
https://api-platform.com/
Standardization
Kafka messages without avro schema is the best way to make debugging a
nightmare.
Also please do not serialize 1 MB of data in kafka please, Kafka is not MySql.
Testing
Testing positive cases only
is not great idea
Logging
Logging
“It’s not working”
Logging
“We do not know what happened”.
“This is my best guess”.
“It’s only 1 customer of 1000, I’m sure he need to clear the cache.”
Logging
Logs are insurance policy,
you don’t care about it till you need them, then it’s too late.
Bare minimum: please please log any failures to perform external operations or
operations impacting business process.
(dbs, , kafka, curl, … )
Logging
Example of stressful and also useless logging messages
“Error happened”
“Order not processed”
“Life is hard”
Logging
Log level matters,
if everything is WARNING or ERROR then nothing is important.
Observability
“Do you know that your website is down ?”
“A customer called and said he sees something in checkout says 503.”
Observability
Create alert for website downtime.
Also watch the business impact,
“no orders in the last hour”.
Simplest tool is uptimerobot , similar tools.
Observability
Watching/having-and-alert for error logs.
Simplest tool is sentry.io, similar tools.
Continuous integration
The team discussed best practices, and after a lengthy discussion, they agreed.
Continuous integration
Best practices are amazing, but we are humans, we always do mistakes.
“We are only humans” said by ahmed , 11 sep 2020
Automate anything you can in your application pipelines, save your team the
hassle.
Gitlab ci, bitbucket ci, circle ci, buildkite ci, …..
Containers
Docker is a company with a tool after it’s name.
The technology name is containers.
Please use “containers” instead of “docker”.
Containers
In short, containers images are compressed archives contains
- your application code itself
- The binaries that run it (php fpm)
- The binaries config (php.ini)
Containers
Please use aggressive opcache options on docker/containers on PROD
Opcache.validate_timestamps => 0
Each deployment is a new container with new memory,
no need to worry about this.
Containers
Storage in containers are ephemeral,
please do not attempt to write on it or use for anything,
even for logging, especially for logging.
Use GCS or AWS S3 or anything else.
Send logs to centralized logging.
Containers
Containers startup time should be very very small
In other words:
Composer install on container startup is a bad idea.
Npm install on on container startup is a a bad idea.
Containers
The same container image must be
deployable to production, staging and local.
If not, debugging becomes impossible and testing extremely hard.
More resources
Video: PHPUnit Best Practices (Sebastian Bergmann)
Video collection: Best practices in PHP
Article: Eliminating Visual Debt
Questions ?
Thank you for listening
Twitter: ama_abdou
WWW: ahmd.io

More Related Content

What's hot (20)

PDF
The Power Of Refactoring (PHPNW)
Stefan Koopmanschap
 
PDF
Cucumber.js: Cuke up your JavaScript!
Julien Biezemans
 
PPTX
HTML5 for dummies
Ran Bar-Zik
 
PDF
Automate Yo' Self
John Anderson
 
PDF
TGT#20 - Automated Tests Only For Testers - Kasper Kulikowski
Trójmiejska Grupa Testerska
 
PDF
It's all about behaviour, also in php - phpspec
Giulio De Donato
 
PPTX
Follow these reasons to know java’s importance
nishajj
 
PDF
Myphp-busters: symfony framework (PHPCon.it)
Stefan Koopmanschap
 
PDF
那些年,我們一起玩的萬花筒(Kaliedoscopic)
PRADA Hsiung
 
PDF
Myphp-busters: symfony framework
Stefan Koopmanschap
 
PPT
Testing Storm components with Groovy and Spock
Eugene Dvorkin
 
PDF
BDD in PHP - Behat
Łukasz Kużyński
 
PDF
composer_talk_20160209
Bradley Wogsland
 
PPTX
REPL-driven development with pry
Stephen Mariano Cabrera
 
PPTX
Lessons Learned From Applications That Kicked Titanium's Ass
Kevin Whinnery
 
PPTX
Behat - human-readable automated testing
nyccamp
 
ODP
BDD with Behat
Richard Shank
 
PPTX
scriptcs - scripted C#, REPL and script extensibility
Filip W
 
PDF
Node & Express as Workflow Tools
FITC
 
The Power Of Refactoring (PHPNW)
Stefan Koopmanschap
 
Cucumber.js: Cuke up your JavaScript!
Julien Biezemans
 
HTML5 for dummies
Ran Bar-Zik
 
Automate Yo' Self
John Anderson
 
TGT#20 - Automated Tests Only For Testers - Kasper Kulikowski
Trójmiejska Grupa Testerska
 
It's all about behaviour, also in php - phpspec
Giulio De Donato
 
Follow these reasons to know java’s importance
nishajj
 
Myphp-busters: symfony framework (PHPCon.it)
Stefan Koopmanschap
 
那些年,我們一起玩的萬花筒(Kaliedoscopic)
PRADA Hsiung
 
Myphp-busters: symfony framework
Stefan Koopmanschap
 
Testing Storm components with Groovy and Spock
Eugene Dvorkin
 
BDD in PHP - Behat
Łukasz Kużyński
 
composer_talk_20160209
Bradley Wogsland
 
REPL-driven development with pry
Stephen Mariano Cabrera
 
Lessons Learned From Applications That Kicked Titanium's Ass
Kevin Whinnery
 
Behat - human-readable automated testing
nyccamp
 
BDD with Behat
Richard Shank
 
scriptcs - scripted C#, REPL and script extensibility
Filip W
 
Node & Express as Workflow Tools
FITC
 

Similar to PHP Mega Meetup, Sep, 2020, Anti patterns in php (20)

PDF
Standard Coding, OOP Techniques and Code Reuse
Rayhan Chowdhury
 
PDF
Containerizing legacy applications
Andrew Kirkpatrick
 
PDF
Advanced PHP: Design Patterns - Dennis-Jan Broerse
dpc
 
PDF
Fighting legacy with hexagonal architecture and frameworkless php
Fabio Pellegrini
 
KEY
PHP Industrialization
Damien Seguy
 
PPT
Software Engineering in PHP
M A Hossain Tonu
 
PDF
Comment améliorer le quotidien des Développeurs PHP ?
AFUP_Limoges
 
PPTX
Continuous feature-development
nhm taveer hossain khan
 
PPT
Enterprise PHP (PHP London Conference 2008)
Ivo Jansch
 
PDF
Symfony - Introduction
Piers Warmers
 
PDF
"PHP Code Avengers: Structuring, Refactoring, and Superhero Practices", Vlad...
Fwdays
 
PDF
Symfony2: Get your project started
Ryan Weaver
 
PPTX
Introduction to PHP Development in Vadodara: Versatility and Innovation
Consumer Sketch
 
ODP
Building Scalable Development Environments
Shahar Evron
 
ODP
Best practices tekx
Lorna Mitchell
 
PDF
Reduce Reuse Refactor
Alena Holligan
 
PDF
So You Just Inherited a $Legacy Application...
Joe Ferguson
 
PDF
Throwing Laravel into your Legacy App™
Joe Ferguson
 
PDF
From dev to ops and beyond - getting it done
Edorian
 
PDF
Php Development Best Practices
phandungtienvn
 
Standard Coding, OOP Techniques and Code Reuse
Rayhan Chowdhury
 
Containerizing legacy applications
Andrew Kirkpatrick
 
Advanced PHP: Design Patterns - Dennis-Jan Broerse
dpc
 
Fighting legacy with hexagonal architecture and frameworkless php
Fabio Pellegrini
 
PHP Industrialization
Damien Seguy
 
Software Engineering in PHP
M A Hossain Tonu
 
Comment améliorer le quotidien des Développeurs PHP ?
AFUP_Limoges
 
Continuous feature-development
nhm taveer hossain khan
 
Enterprise PHP (PHP London Conference 2008)
Ivo Jansch
 
Symfony - Introduction
Piers Warmers
 
"PHP Code Avengers: Structuring, Refactoring, and Superhero Practices", Vlad...
Fwdays
 
Symfony2: Get your project started
Ryan Weaver
 
Introduction to PHP Development in Vadodara: Versatility and Innovation
Consumer Sketch
 
Building Scalable Development Environments
Shahar Evron
 
Best practices tekx
Lorna Mitchell
 
Reduce Reuse Refactor
Alena Holligan
 
So You Just Inherited a $Legacy Application...
Joe Ferguson
 
Throwing Laravel into your Legacy App™
Joe Ferguson
 
From dev to ops and beyond - getting it done
Edorian
 
Php Development Best Practices
phandungtienvn
 
Ad

More from Ahmed Abdou (7)

PDF
Opesnource and jobs
Ahmed Abdou
 
PDF
Cloud and Devops
Ahmed Abdou
 
PDF
About Linux , Shake your brain
Ahmed Abdou
 
ODP
Future is now,Future is Opensource
Ahmed Abdou
 
PDF
You're open source
Ahmed Abdou
 
PDF
المصادر المفتوحة , فرصة
Ahmed Abdou
 
PDF
Menufya SFD 2012
Ahmed Abdou
 
Opesnource and jobs
Ahmed Abdou
 
Cloud and Devops
Ahmed Abdou
 
About Linux , Shake your brain
Ahmed Abdou
 
Future is now,Future is Opensource
Ahmed Abdou
 
You're open source
Ahmed Abdou
 
المصادر المفتوحة , فرصة
Ahmed Abdou
 
Menufya SFD 2012
Ahmed Abdou
 
Ad

Recently uploaded (20)

PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PPTX
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
PPTX
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PDF
Learn Computer Forensics, Second Edition
AnuraShantha7
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PPTX
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
Learn Computer Forensics, Second Edition
AnuraShantha7
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 

PHP Mega Meetup, Sep, 2020, Anti patterns in php

  • 3. Who is this guy ? ● Ahmed ● In the industry for about 9 years, I worked as SRE, PM but mostly Software engineer. ● I love all languages but PHP a little bit more. ● Opensource advocate.
  • 5. ● Low cost, high-risk actions. ● Composer. ● Inheritance. ● Standardization ● Testing ● Logging ● Observability ● Continuous integration ● Containers Anti-patterns in php
  • 6. Low cost, high-risk actions Anti-patterns in php
  • 7. PHP is easy and makes everything sounds that everything will work correctly on it's own. Low cost, high-risk actions
  • 8. Low cost, high-risk actions After you deploy your app to production, always expect: - To be asked to extend certain feature. - Add new feature. - To get bug reports and be able to understand it and fix it.
  • 9. Low cost, high-risk actions Every technical action makes it easier or harder to : - Quickly modify the code base and make the PMs/CXOs happy. - Make you and your teammates happy when they fix a bug.
  • 10. So, while coding ... Anti-patterns in php
  • 11. Composer Please, please, do not use the Death Star, The Death Star is a bomb waiting to explode in the team face always use version constraints.
  • 12. Composer Please do not edit composer files manually at all Please, please, use composer commands, they are super easy. “The new composer package is working locally but not working on the server”
  • 13. Extending classes ● Each parent should not many children. It becomes hard to change the parent even with 100% testing coverage. ● System design is thrown out of the window with the overuse of inheritance, easy solutions like visibility change for the sake of easiness over-power the design and leads to GOD-classes eventually very easily. ● This is the exact recipe to create a bad monolith
  • 14. Extending classes Inheritance is not the only way to extend a functionality. Also taxes are high on inheritance these days.
  • 15. Extending classes Inheritance is not the only way to extend a functionality, for example composition. https://en.wikipedia.org/wiki/Composition_over_inheritance Fun Fun Function: Composition over Inheritance
  • 16. Depending on the environment Avoid depending on the environment, for example Instead: you can use environment variables “I can not test it, It works only on PROD”
  • 20. Standardization API with no OpenAPI/Swagger specs is not an API. But It’s a good way to waste time and frustration everyone. https://github.com/zircote/swagger-php https://api-platform.com/
  • 21. Standardization Kafka messages without avro schema is the best way to make debugging a nightmare. Also please do not serialize 1 MB of data in kafka please, Kafka is not MySql.
  • 22. Testing Testing positive cases only is not great idea
  • 25. Logging “We do not know what happened”. “This is my best guess”. “It’s only 1 customer of 1000, I’m sure he need to clear the cache.”
  • 26. Logging Logs are insurance policy, you don’t care about it till you need them, then it’s too late. Bare minimum: please please log any failures to perform external operations or operations impacting business process. (dbs, , kafka, curl, … )
  • 27. Logging Example of stressful and also useless logging messages “Error happened” “Order not processed” “Life is hard”
  • 28. Logging Log level matters, if everything is WARNING or ERROR then nothing is important.
  • 29. Observability “Do you know that your website is down ?” “A customer called and said he sees something in checkout says 503.”
  • 30. Observability Create alert for website downtime. Also watch the business impact, “no orders in the last hour”. Simplest tool is uptimerobot , similar tools.
  • 31. Observability Watching/having-and-alert for error logs. Simplest tool is sentry.io, similar tools.
  • 32. Continuous integration The team discussed best practices, and after a lengthy discussion, they agreed.
  • 33. Continuous integration Best practices are amazing, but we are humans, we always do mistakes. “We are only humans” said by ahmed , 11 sep 2020 Automate anything you can in your application pipelines, save your team the hassle. Gitlab ci, bitbucket ci, circle ci, buildkite ci, …..
  • 34. Containers Docker is a company with a tool after it’s name. The technology name is containers. Please use “containers” instead of “docker”.
  • 35. Containers In short, containers images are compressed archives contains - your application code itself - The binaries that run it (php fpm) - The binaries config (php.ini)
  • 36. Containers Please use aggressive opcache options on docker/containers on PROD Opcache.validate_timestamps => 0 Each deployment is a new container with new memory, no need to worry about this.
  • 37. Containers Storage in containers are ephemeral, please do not attempt to write on it or use for anything, even for logging, especially for logging. Use GCS or AWS S3 or anything else. Send logs to centralized logging.
  • 38. Containers Containers startup time should be very very small In other words: Composer install on container startup is a bad idea. Npm install on on container startup is a a bad idea.
  • 39. Containers The same container image must be deployable to production, staging and local. If not, debugging becomes impossible and testing extremely hard.
  • 40. More resources Video: PHPUnit Best Practices (Sebastian Bergmann) Video collection: Best practices in PHP Article: Eliminating Visual Debt
  • 41. Questions ? Thank you for listening Twitter: ama_abdou WWW: ahmd.io