SlideShare a Scribd company logo
PHP RULES
1)Go OOP



          If you have not yet entered the realm of Object Oriented
           Programming, then you are at a disadvantage, and you are falling
           behind fast.

          OOP is essentially a method of programming with the use of
           classes, or Objects, which tie like things together, remove the need
           for repetition of code and perform the basic tasks of production very
           simply. Objects are essentially classes that collect a bunch of
           functions together and wrap them in a wrapper that can be reused
           over and over again without the need to rewrite functionality or
           procedures every time you need to do something.

          Procedural Programming works by following a routine from the top to
           the bottom of each page as the server reads every file on your
           server. With OOP, there could be one or two objects being
           instantiated, which, in turn could instantiate a few, a hundred or a
           thousand other objects which could all perform certain tasks
           depending on variables passed into the objects. OOP is
           faster, simpler, easier to debug, uses less server resources, less
           code, is faster loading and more logical to work with once you figure
           out the basic principles. Go OOP - It changed my development style
           forever.
2) Stay Away from Anything Ending With _once()




           We all know that include() simply gives us a warning if it fails, while
            require() kills the script with a fatal error when it fails. What we don't
            forget is that include_once() and require_once() is extremely hard on
            server resources. There is nothing we can do about it, it's how PHP
            is set up. Just remember that these things kill your server
            resources, specially on a huge framework, and if you plan your code
            properly you won't even need it anyway.
3) Develop With Error Reporting On




           The very first thing you do when starting a new project is to turn error
            reporting to E_ALL, and you should only turn it off ten seconds
            before going to production mode. I do this with every project that I
            build and there is nothing better than running a project in full
            production mode and not even getting one error. Besides that, with
            error reporting on, you pick up any small errors that will eventually
            grow up to bite you in the... well, you get my point.
5) Use PHP's Inbuilt Functions




           Ok, you want to count the amount of keys in an array? You can loop
            through the array and simply increment a value for each iteration,
            right? Or you can just use the built in PHP function count(), which
            does just what it should. PHP has many built-in functions that can do
            what you need them to, so check out the manual to make sure you
            are doing it in the best way possible
6) Protect Your Database




           The best and safest way is to use mysql_real_escape_string() for all
            database before it is added to the database. This function makes all
            strings safe in terms of quotes and other functions that can harm
            your database or contain malicious code, so use it to be sure you
            have taken the first step against protection of your data. Another
            thing you can do is validate all POST and GET strings, never use
            $_REQUEST, and make sure all form submitted data is of the right
            type and value before adding it to a database query.
7) Use POST Not GET




          Ok, this isn't always possible, but when its really not necessary, don't
           use GET, use POST. The reason is simple - GET is simple to
           emulate, all I need to do is add something to my address bar and I
           can hack your project. Obviously GET is the easy way to do
           pagination and permalinks, but when using form submission
           especially, stay with POST, it's safer.
8) Draw Before You Code




          A good practice to get into is to wireframe your projects, even if you
           are just scribbling a few notes on a piece of paper. It is very
           important to actually give the mechanics of you application some
           thought before sitting down to start coding, because in the process of
           planning it you will actually iron out the difficulties in your head and
           avoid the major headache that comes with the facepalm when you
           realize that everything you just did is either wrong, not needed, or
           just silly.
9) Understand Your Project




           An artist cannot draw something that he has not seen before. A
            singer cannot sing a song that he has not heard before. You cannot
            code a project that you do not fully understand. If you do not
            understand exactly what it needs to do, and how it needs to it, you
            cannot build it.
10) Code Code Code




          If I could get one thing through to anyone reading this, this is it. You
           cannot become a good developer by reading. You cannot become a
           good developer by watching someone develop. The one and only
           tried and trusted method, is to actually write code. But - and here is
           the trick - build real things! Do not go and code something that you
           have no interest in, or will never use. Build what you like, and you
           will be excited and interested by it, and you will learn. Then, make it
           awesome, build upon it, and make it better.
4) Use A Framework If You Need One




           Ok, so Rasmus Lerdorf says you shouldn't use a framework because
            he could quite conclusively prove that a framework is much slower
            than normal PHP code when it came to printing a simple "Hello
            World" application. Two things to mention here though: you are not
            Rasmus Lerdorf and I bet you won't be building a "Hello World"
            application every time you program something. Frameworks that
            help you do the tedious things can help, although you will have to
            learn how the frameworks function first in order to make things
            simple, but that's the only real trade-off. Plus you stand less chance
            of writing bad code when someone else has written most of it for
            you, but let's pretend I didn't say that.

More Related Content

PDF
Repoze Bfg - presented by Rok Garbas at the Python Barcelona Meetup October 2...
PDF
Enterprise PHP (php|works 2008)
PPTX
What to expect while building your first nodeJS application
PPTX
2012_kazakov_p_n_environmental_security_and_life_support_system_of_dwelling
PPT
Lunjev innosalon 2013_05_23
PPT
Lebedev presentation 2013-04-11
PPSX
Cyber.jaf presentation
PPT
2012 andieva e_ju_innovative_management_of_complex_software_projects
Repoze Bfg - presented by Rok Garbas at the Python Barcelona Meetup October 2...
Enterprise PHP (php|works 2008)
What to expect while building your first nodeJS application
2012_kazakov_p_n_environmental_security_and_life_support_system_of_dwelling
Lunjev innosalon 2013_05_23
Lebedev presentation 2013-04-11
Cyber.jaf presentation
2012 andieva e_ju_innovative_management_of_complex_software_projects

Viewers also liked (13)

PPT
2012_chagina_a_v_business_incubation_as_an_element_of_the_system_of_the_devel...
PPT
Lizunov forum iv-conf-s_2013-05-28
PPTX
Join Axis CC thru LR
PPTX
PDF
U.S. Airlines: Their Nascent Recovery and the Benefits to the Nation
PPT
2012_kuzheva_s_n_financial_aspects_of_formation_of_innovative_potential_of_th...
PPT
Publics.bg 2012 Portfolio
PPTX
Markswebb Rank & Report: 10 советов, как сделать лучший интернет-банк
PPT
E business-ppt
PPT
Timkin presentation 2013-10-17
PDF
Regular seminar OM
PPT
2012_lizunov_v_v_the_strategic_directions_of_development_of_the_omsk_region
2012_chagina_a_v_business_incubation_as_an_element_of_the_system_of_the_devel...
Lizunov forum iv-conf-s_2013-05-28
Join Axis CC thru LR
U.S. Airlines: Their Nascent Recovery and the Benefits to the Nation
2012_kuzheva_s_n_financial_aspects_of_formation_of_innovative_potential_of_th...
Publics.bg 2012 Portfolio
Markswebb Rank & Report: 10 советов, как сделать лучший интернет-банк
E business-ppt
Timkin presentation 2013-10-17
Regular seminar OM
2012_lizunov_v_v_the_strategic_directions_of_development_of_the_omsk_region
Ad

Similar to Php rules (20)

PDF
Surviving a Hackathon and Beyond
PDF
Writing Readable Code
PDF
Maintainable Javascript carsonified
PDF
Rasmus, Think Again! Agile Framework == Happy Php Developer
KEY
Social dev camp_2011
PPTX
Untangling spring week8
PDF
Top 10 techniques to minimize security vulnerabilities in php application dev...
PDF
Becoming A Php Ninja
PDF
Class 6: Introduction to web technology entrepreneurship
PPT
Software Engineering in PHP
PDF
Best practices-wordpress-enterprise
PPT
Scaling Web Apps P Falcone
PDF
5 best practices for (web/ software) development (2010)
PDF
How Not Php
ODP
Basics of-software-development
PPTX
Best Practices for WordPress in Enterprise
PDF
Why You're A Bad PHP Programmer
PDF
WordCamp US: Clean Code
PDF
Enterprise PHP
PDF
Django in the Real World
Surviving a Hackathon and Beyond
Writing Readable Code
Maintainable Javascript carsonified
Rasmus, Think Again! Agile Framework == Happy Php Developer
Social dev camp_2011
Untangling spring week8
Top 10 techniques to minimize security vulnerabilities in php application dev...
Becoming A Php Ninja
Class 6: Introduction to web technology entrepreneurship
Software Engineering in PHP
Best practices-wordpress-enterprise
Scaling Web Apps P Falcone
5 best practices for (web/ software) development (2010)
How Not Php
Basics of-software-development
Best Practices for WordPress in Enterprise
Why You're A Bad PHP Programmer
WordCamp US: Clean Code
Enterprise PHP
Django in the Real World
Ad

Recently uploaded (20)

PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
NewMind AI Monthly Chronicles - July 2025
PPTX
Big Data Technologies - Introduction.pptx
PPT
Teaching material agriculture food technology
PDF
Review of recent advances in non-invasive hemoglobin estimation
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
cuic standard and advanced reporting.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Modernizing your data center with Dell and AMD
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Machine learning based COVID-19 study performance prediction
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
NewMind AI Monthly Chronicles - July 2025
Big Data Technologies - Introduction.pptx
Teaching material agriculture food technology
Review of recent advances in non-invasive hemoglobin estimation
The AUB Centre for AI in Media Proposal.docx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Per capita expenditure prediction using model stacking based on satellite ima...
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
Mobile App Security Testing_ A Comprehensive Guide.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Encapsulation_ Review paper, used for researhc scholars
Building Integrated photovoltaic BIPV_UPV.pdf
cuic standard and advanced reporting.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
Modernizing your data center with Dell and AMD
Chapter 3 Spatial Domain Image Processing.pdf
Machine learning based COVID-19 study performance prediction

Php rules

  • 2. 1)Go OOP  If you have not yet entered the realm of Object Oriented Programming, then you are at a disadvantage, and you are falling behind fast.  OOP is essentially a method of programming with the use of classes, or Objects, which tie like things together, remove the need for repetition of code and perform the basic tasks of production very simply. Objects are essentially classes that collect a bunch of functions together and wrap them in a wrapper that can be reused over and over again without the need to rewrite functionality or procedures every time you need to do something.  Procedural Programming works by following a routine from the top to the bottom of each page as the server reads every file on your server. With OOP, there could be one or two objects being instantiated, which, in turn could instantiate a few, a hundred or a thousand other objects which could all perform certain tasks depending on variables passed into the objects. OOP is faster, simpler, easier to debug, uses less server resources, less code, is faster loading and more logical to work with once you figure out the basic principles. Go OOP - It changed my development style forever.
  • 3. 2) Stay Away from Anything Ending With _once()  We all know that include() simply gives us a warning if it fails, while require() kills the script with a fatal error when it fails. What we don't forget is that include_once() and require_once() is extremely hard on server resources. There is nothing we can do about it, it's how PHP is set up. Just remember that these things kill your server resources, specially on a huge framework, and if you plan your code properly you won't even need it anyway.
  • 4. 3) Develop With Error Reporting On  The very first thing you do when starting a new project is to turn error reporting to E_ALL, and you should only turn it off ten seconds before going to production mode. I do this with every project that I build and there is nothing better than running a project in full production mode and not even getting one error. Besides that, with error reporting on, you pick up any small errors that will eventually grow up to bite you in the... well, you get my point.
  • 5. 5) Use PHP's Inbuilt Functions  Ok, you want to count the amount of keys in an array? You can loop through the array and simply increment a value for each iteration, right? Or you can just use the built in PHP function count(), which does just what it should. PHP has many built-in functions that can do what you need them to, so check out the manual to make sure you are doing it in the best way possible
  • 6. 6) Protect Your Database  The best and safest way is to use mysql_real_escape_string() for all database before it is added to the database. This function makes all strings safe in terms of quotes and other functions that can harm your database or contain malicious code, so use it to be sure you have taken the first step against protection of your data. Another thing you can do is validate all POST and GET strings, never use $_REQUEST, and make sure all form submitted data is of the right type and value before adding it to a database query.
  • 7. 7) Use POST Not GET  Ok, this isn't always possible, but when its really not necessary, don't use GET, use POST. The reason is simple - GET is simple to emulate, all I need to do is add something to my address bar and I can hack your project. Obviously GET is the easy way to do pagination and permalinks, but when using form submission especially, stay with POST, it's safer.
  • 8. 8) Draw Before You Code  A good practice to get into is to wireframe your projects, even if you are just scribbling a few notes on a piece of paper. It is very important to actually give the mechanics of you application some thought before sitting down to start coding, because in the process of planning it you will actually iron out the difficulties in your head and avoid the major headache that comes with the facepalm when you realize that everything you just did is either wrong, not needed, or just silly.
  • 9. 9) Understand Your Project  An artist cannot draw something that he has not seen before. A singer cannot sing a song that he has not heard before. You cannot code a project that you do not fully understand. If you do not understand exactly what it needs to do, and how it needs to it, you cannot build it.
  • 10. 10) Code Code Code  If I could get one thing through to anyone reading this, this is it. You cannot become a good developer by reading. You cannot become a good developer by watching someone develop. The one and only tried and trusted method, is to actually write code. But - and here is the trick - build real things! Do not go and code something that you have no interest in, or will never use. Build what you like, and you will be excited and interested by it, and you will learn. Then, make it awesome, build upon it, and make it better.
  • 11. 4) Use A Framework If You Need One  Ok, so Rasmus Lerdorf says you shouldn't use a framework because he could quite conclusively prove that a framework is much slower than normal PHP code when it came to printing a simple "Hello World" application. Two things to mention here though: you are not Rasmus Lerdorf and I bet you won't be building a "Hello World" application every time you program something. Frameworks that help you do the tedious things can help, although you will have to learn how the frameworks function first in order to make things simple, but that's the only real trade-off. Plus you stand less chance of writing bad code when someone else has written most of it for you, but let's pretend I didn't say that.