SlideShare a Scribd company logo
1 of 49
Download to read offline
Everyday Best Practices
for PHP Development
Matthew Weier O'Phinney
Software Architect,
Zend Technologies

        What you can do to make your life and your
        team's lives easier.




                      Copyright © 2008, Zend Technologies Inc.
What will I gain?

  • Test your code instead of debug it
  • Discover issues before you deploy your
    code
  • Documentation of your code
  • Documentation for your users
  • Better communication with your team
  • and, bottom line, maintainability.




  Dutch PHP Conference             14 June 2008   | Page 2
The single best practice...




                         TEST!

  Dutch PHP Conference           14 June 2008   | Page 3
Test?

  • Unit test everything you can
  • Learn how to do functional and integration testing
  • Don't put it off




  Dutch PHP Conference                    14 June 2008   | Page 4
Benefits of testing

  • More testing == Less debugging
  • Revise and exercise your object APIs before
      writing code
  •   Instant feedback when changes are made
  •   Repeatable
  •   Stabilize functionality
  •   Gain confidence in your application quality
  •   ...




  Dutch PHP Conference                     14 June 2008   | Page 5
Benefits of testing

  • Do you really need more reasons?




  Dutch PHP Conference                 14 June 2008   | Page 6
Test behaviors in your models

  • Example:
    I should be able to fetch a user by email




  Dutch PHP Conference                    14 June 2008   | Page 7
Extend testing to your applications

  • Given a request to /foo/bar, I should have at least
    2 items matching the CSS selector “div#foo
    legend.bar”:




  Dutch PHP Conference                    14 June 2008   | Page 8
Get to know PHPUnit

  • http://phpunit.de/




  Dutch PHP Conference   14 June 2008   | Page 9
And another gem:




       Use a
  Coding Standard

  Dutch PHP Conference   14 June 2008   | Page 10
Why use coding standards?

 • Focus on code, not formatting
 • Consistency
 • Readability
 • Collaboration




  Dutch PHP Conference             14 June 2008   | Page 11
Okay, I'll create one...




                         STOP!

  Dutch PHP Conference           14 June 2008   | Page 12
Learn from others

  • The issues have already been debated to death.
  • Use an established standard, and stick to it.
       Minimizes politics when choosing
       Choose a standard compatible with the libraries or
        frameworks you use
       Use the standard as a requirement for hiring or
        outsourcing.




  Dutch PHP Conference                            14 June 2008   | Page 13
What does a standard provide?

 • File, class, and variable naming conventions
 • Code formatting conventions




  Dutch PHP Conference                  14 June 2008   | Page 14
Some Zend Framework standards

 • Derived from PEAR standards (which were in turn
    derived from Horde standards)

 • One class, one file
 • Underscores in class names map to directory
    separators:
    Zend_Controller_Action:
    Zend/Controller/Action.php




  Dutch PHP Conference                 14 June 2008   | Page 15
Some Zend Framework standards

 Naming conventions:
 • Class names are MixedCase
 • Method names are camelCase
 • Constants are ALL_CAPS
 • Properties and variables are camelCase
 • Private and protected members are
    _underscorePrefixed




  Dutch PHP Conference                14 June 2008   | Page 16
Some Zend Framework standards

 Layout Conventions:
 • No closing ?> tag for files containing only code
 • Indentation: spaces only, no tabs; 4 spaces per
     level of indentation
 •   One True Brace:
       Classes and methods place opening brace on following
        line at same indentation.
       Logical structures place opening brace on same line.
       All control structures use braces, period.
 • No shell style comments (#)
 • Keep lines no more than 75-85 characters long

  Dutch PHP Conference                          14 June 2008   | Page 17
Example




  Dutch PHP Conference   14 June 2008   | Page 18
What else should you know?




      Design Patterns

  Dutch PHP Conference       14 June 2008   | Page 19
What are those?

 • Reusable ideas, not code
 • Proven solutions to common design problems
 • Better communication through shared vocabulary




  Dutch PHP Conference               14 June 2008   | Page 20
Some examples, please?

 • I need to be able to notify other objects when I
     execute a particular event: Observer
 •   I need to be able to mutate the backend object
     to which I delegate: Adapter
 •   I need to modify the output of an object:
     Decorator
 •   I need to decorate my application output with
     general site content: Two Step View




  Dutch PHP Conference                   14 June 2008   | Page 21
Who uses design patterns?

  • Frameworks; Zend Framework is riddled with them

  • You do, by using frameworks. :-)




  Dutch PHP Conference                 14 June 2008   | Page 22
What next?




       Documentation

  Dutch PHP Conference   14 June 2008   | Page 23
But I don't have time!

  • You don't have time to code?




  Dutch PHP Conference             14 June 2008   | Page 24
API documentation is easy

  • Simply prepend PHP docblocks to your methods
    and classes; your IDE will often do it for you:




  Dutch PHP Conference                      14 June 2008   | Page 25
What can I document this way?

 • Classes, methods, class properties...
 • Use annotation tags in source comments to
    provide context:
    @param, @return, @throws, @see, @todo




  Dutch PHP Conference                 14 June 2008   | Page 26
Docblocks can organize code

 • Utilize @category, @package, @subpackage;
     phpDoc uses these to organize documentation.
 •   Prefix your classes; easier to browse, and easier to
     mix with other libraries.




  Dutch PHP Conference                      14 June 2008   | Page 27
Generate pretty API docs

  • phpDocumentor:
    http://phpdoc.org/

  • Doxygen: http://www.stack.nl/~dimitri/doxygen/




  Dutch PHP Conference                 14 June 2008   | Page 28
See?




  Dutch PHP Conference   14 June 2008   | Page 29
Be careful what you say...

  • Docblocks can go out of date. Be general, except
      when it comes to the parameters and return
      values.
  •   When in doubt, unit tests don't lie.




  Dutch PHP Conference                    14 June 2008   | Page 30
IDEs like documentation, too

  • IDE's introspect DocBlocks to provide typehinting,
    return values, and method descriptions.




  Dutch PHP Conference                    14 June 2008   | Page 31
So does Zend Framework!

 • Various Server classes utilize DocBlocks to provide
    hinting for parameter and return value types, as
    well as method descriptions
       Zend_XmlRpc_Server
       Zend_Rest_Server
       Zend_Json_Server (coming soon!)
       Zend_Soap_Wsdl (coming soon!)
       Zend_Tool (coming soon!)




  Dutch PHP Conference                    14 June 2008   | Page 32
Don't forget your users!

  • End users like to know how to use your code and
      applications
  •   Give them a manual!




  Dutch PHP Conference                  14 June 2008   | Page 33
XML is not a four-letter word

  • DocBook is the most common format for open
      source documentation
  •   DocBook can be compiled to a variety of formats:
      HTML, Windows Help files (CHM), PDF, and more.
  •   Often used by book publishers (O'Reilly)
  •   It powers the PHP.net manual
  •   It powers Zend Framework's manual




  Dutch PHP Conference                    14 June 2008   | Page 34
DocBook is easy




  Dutch PHP Conference   14 June 2008   | Page 35
One possible rendition:




  Dutch PHP Conference    14 June 2008   | Page 36
Don't forget to backup...




  Source Control

  Dutch PHP Conference      14 June 2008   | Page 37
Why do I need it?

  • How do I know if somebody did something?
  • How do others know I did something?
  • How do I get my updates from others?
  • How do I push my updates out to others?
  • Do we have the old version? What changed?




  Dutch PHP Conference                14 June 2008   | Page 38
What are my options?

 • Distributed Source Control:
    Developers work on their own repositories and
    share changesets
       Git
       Darcs
       Arch
 • Non-Distributed Source Control
    Developers work on local checkouts, and check
    in to a central repository
       Subversion




  Dutch PHP Conference                  14 June 2008   | Page 39
How do I use source control?

  • Perform local checkout
  • Write code
  • Record changes
  • Check changes in to repository
  • Check for repository updates
  • Lather, rinse, repeat




  Dutch PHP Conference               14 June 2008   | Page 40
What do you use?

 Subversion
 • Extensible and supported by excellent tools
       Write scripts to perform actions before and after
         checkins
 • Popular with many open source projects;
     integrate with them using svn:externals
 •   Easily move files between directories while
     preserving histories
 •   Simplified process of tagging and branching
 •   Transactions for when things go wrong



  Dutch PHP Conference                            14 June 2008   | Page 41
Review

Dutch PHP Conference            14 June 2008   | Page 42
How do I make my life easier?

  • TEST!




  Dutch PHP Conference          14 June 2008   | Page 43
How do I make my life easier?

  • TEST!
  • Use a coding standard




  Dutch PHP Conference          14 June 2008   | Page 44
How do I make my life easier?

  • TEST!
  • Use a coding standard
  • Learn and utilize design patterns




  Dutch PHP Conference                  14 June 2008   | Page 45
How do I make my life easier?

  • TEST!
  • Use a coding standard
  • Learn and utilize design patterns
  • Document my code




  Dutch PHP Conference                  14 June 2008   | Page 46
How do I make my life easier?

  • TEST!
  • Use a coding standard
  • Learn and utilize design patterns
  • Document my code
  • Document my application




  Dutch PHP Conference                  14 June 2008   | Page 47
How do I make my life easier?

  • TEST!
  • Use a coding standard
  • Learn and utilize design patterns
  • Document my code
  • Document my application
  • Use source control




  Dutch PHP Conference                  14 June 2008   | Page 48
So what are you
waiting for?


         Thanks for listening!




                    Copyright © 2008, Zend Technologies Inc.

More Related Content

What's hot

Delphi developer certification study guide
Delphi developer certification study guideDelphi developer certification study guide
Delphi developer certification study guideANIL MAHADEV
 
Python Intro For Managers
Python Intro For ManagersPython Intro For Managers
Python Intro For ManagersAtul Shridhar
 
Advanced IDE functionality in modern language workbenches
Advanced IDE functionality in modern language workbenchesAdvanced IDE functionality in modern language workbenches
Advanced IDE functionality in modern language workbenchesVaclav Pech
 
Web programming UNIT II by Bhavsingh Maloth
Web programming UNIT II by Bhavsingh MalothWeb programming UNIT II by Bhavsingh Maloth
Web programming UNIT II by Bhavsingh MalothBhavsingh Maloth
 
Mark asoi ppt
Mark asoi pptMark asoi ppt
Mark asoi pptmark-asoi
 
Concepts of JetBrains MPS
Concepts of JetBrains MPSConcepts of JetBrains MPS
Concepts of JetBrains MPSVaclav Pech
 
Fundamentals of programming final santos
Fundamentals of programming final santosFundamentals of programming final santos
Fundamentals of programming final santosAbie Santos
 

What's hot (14)

Delphi Certification
Delphi CertificationDelphi Certification
Delphi Certification
 
Tech talk webtech
Tech talk webtechTech talk webtech
Tech talk webtech
 
Delphi developer certification study guide
Delphi developer certification study guideDelphi developer certification study guide
Delphi developer certification study guide
 
Fosdem 2011 odt2daisy odt2braille
Fosdem 2011 odt2daisy odt2brailleFosdem 2011 odt2daisy odt2braille
Fosdem 2011 odt2daisy odt2braille
 
JSX Optimizer
JSX OptimizerJSX Optimizer
JSX Optimizer
 
Zend Framework Workshop
Zend Framework WorkshopZend Framework Workshop
Zend Framework Workshop
 
Php
PhpPhp
Php
 
Python Intro For Managers
Python Intro For ManagersPython Intro For Managers
Python Intro For Managers
 
Advanced IDE functionality in modern language workbenches
Advanced IDE functionality in modern language workbenchesAdvanced IDE functionality in modern language workbenches
Advanced IDE functionality in modern language workbenches
 
Web programming UNIT II by Bhavsingh Maloth
Web programming UNIT II by Bhavsingh MalothWeb programming UNIT II by Bhavsingh Maloth
Web programming UNIT II by Bhavsingh Maloth
 
Mark asoi ppt
Mark asoi pptMark asoi ppt
Mark asoi ppt
 
Concepts of JetBrains MPS
Concepts of JetBrains MPSConcepts of JetBrains MPS
Concepts of JetBrains MPS
 
Fundamentals of programming final santos
Fundamentals of programming final santosFundamentals of programming final santos
Fundamentals of programming final santos
 
Html5 - Tutorial
Html5 - TutorialHtml5 - Tutorial
Html5 - Tutorial
 

Similar to Best Practices with Zend Framework - Matthew Weier O'Phinney

Professional PHP: an open-source alternative for enterprise development [Kort...
Professional PHP: an open-source alternative for enterprise development [Kort...Professional PHP: an open-source alternative for enterprise development [Kort...
Professional PHP: an open-source alternative for enterprise development [Kort...Combell NV
 
Introduction to PHP (SDPHP)
Introduction to PHP   (SDPHP)Introduction to PHP   (SDPHP)
Introduction to PHP (SDPHP)Eric Johnson
 
APIs and SDKs: Breaking Into and Succeeding in a Specialty Market
APIs and SDKs: Breaking Into and Succeeding in a Specialty MarketAPIs and SDKs: Breaking Into and Succeeding in a Specialty Market
APIs and SDKs: Breaking Into and Succeeding in a Specialty MarketScott Abel
 
Introduction to PHP - SDPHP
Introduction to PHP - SDPHPIntroduction to PHP - SDPHP
Introduction to PHP - SDPHPEric Johnson
 
Enterprise PHP Development - ZendCon 2008
Enterprise PHP Development - ZendCon 2008Enterprise PHP Development - ZendCon 2008
Enterprise PHP Development - ZendCon 2008Ivo Jansch
 
DPC2007 Zend Framework (Gaylord Aulke)
DPC2007 Zend Framework (Gaylord Aulke)DPC2007 Zend Framework (Gaylord Aulke)
DPC2007 Zend Framework (Gaylord Aulke)dpc
 
Enterprise PHP (php|works 2008)
Enterprise PHP (php|works 2008)Enterprise PHP (php|works 2008)
Enterprise PHP (php|works 2008)Ivo Jansch
 
Improved PHP Development
Improved PHP DevelopmentImproved PHP Development
Improved PHP DevelopmentPHPBelgium
 
Integrating PHP With System-i using Web Services
Integrating PHP With System-i using Web ServicesIntegrating PHP With System-i using Web Services
Integrating PHP With System-i using Web ServicesIvo Jansch
 
Barcelona Multilanguage
Barcelona MultilanguageBarcelona Multilanguage
Barcelona Multilanguageguest3a6661
 
Professional PHP: an open-source alternative for enterprise development [Antw...
Professional PHP: an open-source alternative for enterprise development [Antw...Professional PHP: an open-source alternative for enterprise development [Antw...
Professional PHP: an open-source alternative for enterprise development [Antw...Combell NV
 
Scripting Recipes for Testers
Scripting Recipes for TestersScripting Recipes for Testers
Scripting Recipes for TestersAdam Goucher
 
What is the best programming language for your web product?
What is the best programming language for your web product?What is the best programming language for your web product?
What is the best programming language for your web product?MobiDev
 
Os Koziarsky
Os KoziarskyOs Koziarsky
Os Koziarskyoscon2007
 
So gelingt der Umstieg von PHP4 auf PHP5: Erneuerung von Geschäftsanwendung...
So gelingt der Umstieg von PHP4 auf  PHP5: Erneuerung von  Geschäftsanwendung...So gelingt der Umstieg von PHP4 auf  PHP5: Erneuerung von  Geschäftsanwendung...
So gelingt der Umstieg von PHP4 auf PHP5: Erneuerung von Geschäftsanwendung...Lars Jankowfsky
 
IDE and Toolset For Magento Development
IDE and Toolset For Magento DevelopmentIDE and Toolset For Magento Development
IDE and Toolset For Magento DevelopmentAbid Malik
 
Top 8 Powerful Tools Developers Use for Laravel Web Development.pdf
Top 8 Powerful Tools Developers Use for Laravel Web Development.pdfTop 8 Powerful Tools Developers Use for Laravel Web Development.pdf
Top 8 Powerful Tools Developers Use for Laravel Web Development.pdfMoonTechnolabsPvtLtd
 
Laird Best Practices Ajax World West2008
Laird Best Practices Ajax World West2008Laird Best Practices Ajax World West2008
Laird Best Practices Ajax World West2008rajivmordani
 

Similar to Best Practices with Zend Framework - Matthew Weier O'Phinney (20)

Professional PHP: an open-source alternative for enterprise development [Kort...
Professional PHP: an open-source alternative for enterprise development [Kort...Professional PHP: an open-source alternative for enterprise development [Kort...
Professional PHP: an open-source alternative for enterprise development [Kort...
 
Introduction to PHP (SDPHP)
Introduction to PHP   (SDPHP)Introduction to PHP   (SDPHP)
Introduction to PHP (SDPHP)
 
APIs and SDKs: Breaking Into and Succeeding in a Specialty Market
APIs and SDKs: Breaking Into and Succeeding in a Specialty MarketAPIs and SDKs: Breaking Into and Succeeding in a Specialty Market
APIs and SDKs: Breaking Into and Succeeding in a Specialty Market
 
Introduction to PHP - SDPHP
Introduction to PHP - SDPHPIntroduction to PHP - SDPHP
Introduction to PHP - SDPHP
 
Becoming A Php Ninja
Becoming A Php NinjaBecoming A Php Ninja
Becoming A Php Ninja
 
Enterprise PHP Development - ZendCon 2008
Enterprise PHP Development - ZendCon 2008Enterprise PHP Development - ZendCon 2008
Enterprise PHP Development - ZendCon 2008
 
DPC2007 Zend Framework (Gaylord Aulke)
DPC2007 Zend Framework (Gaylord Aulke)DPC2007 Zend Framework (Gaylord Aulke)
DPC2007 Zend Framework (Gaylord Aulke)
 
Enterprise PHP (php|works 2008)
Enterprise PHP (php|works 2008)Enterprise PHP (php|works 2008)
Enterprise PHP (php|works 2008)
 
Improved PHP Development
Improved PHP DevelopmentImproved PHP Development
Improved PHP Development
 
Integrating PHP With System-i using Web Services
Integrating PHP With System-i using Web ServicesIntegrating PHP With System-i using Web Services
Integrating PHP With System-i using Web Services
 
Barcelona Multilanguage
Barcelona MultilanguageBarcelona Multilanguage
Barcelona Multilanguage
 
Professional PHP: an open-source alternative for enterprise development [Antw...
Professional PHP: an open-source alternative for enterprise development [Antw...Professional PHP: an open-source alternative for enterprise development [Antw...
Professional PHP: an open-source alternative for enterprise development [Antw...
 
Scripting Recipes for Testers
Scripting Recipes for TestersScripting Recipes for Testers
Scripting Recipes for Testers
 
What is the best programming language for your web product?
What is the best programming language for your web product?What is the best programming language for your web product?
What is the best programming language for your web product?
 
Os Koziarsky
Os KoziarskyOs Koziarsky
Os Koziarsky
 
So gelingt der Umstieg von PHP4 auf PHP5: Erneuerung von Geschäftsanwendung...
So gelingt der Umstieg von PHP4 auf  PHP5: Erneuerung von  Geschäftsanwendung...So gelingt der Umstieg von PHP4 auf  PHP5: Erneuerung von  Geschäftsanwendung...
So gelingt der Umstieg von PHP4 auf PHP5: Erneuerung von Geschäftsanwendung...
 
IDE and Toolset For Magento Development
IDE and Toolset For Magento DevelopmentIDE and Toolset For Magento Development
IDE and Toolset For Magento Development
 
PHP Documentor
PHP DocumentorPHP Documentor
PHP Documentor
 
Top 8 Powerful Tools Developers Use for Laravel Web Development.pdf
Top 8 Powerful Tools Developers Use for Laravel Web Development.pdfTop 8 Powerful Tools Developers Use for Laravel Web Development.pdf
Top 8 Powerful Tools Developers Use for Laravel Web Development.pdf
 
Laird Best Practices Ajax World West2008
Laird Best Practices Ajax World West2008Laird Best Practices Ajax World West2008
Laird Best Practices Ajax World West2008
 

More from dpc

ezComponents - Derick Rethans
ezComponents - Derick RethansezComponents - Derick Rethans
ezComponents - Derick Rethansdpc
 
Software And The Taste Of Mayo - Marco Tabini
Software And The Taste Of Mayo - Marco TabiniSoftware And The Taste Of Mayo - Marco Tabini
Software And The Taste Of Mayo - Marco Tabinidpc
 
Deployment With Subversion - Lorna Mitchell
Deployment With Subversion - Lorna MitchellDeployment With Subversion - Lorna Mitchell
Deployment With Subversion - Lorna Mitchelldpc
 
State Of PHP - Zeev Suraski
State Of PHP - Zeev SuraskiState Of PHP - Zeev Suraski
State Of PHP - Zeev Suraskidpc
 
Symfony 1.1 - Fabien Potencier
Symfony 1.1 - Fabien PotencierSymfony 1.1 - Fabien Potencier
Symfony 1.1 - Fabien Potencierdpc
 
Advanced PHP: Design Patterns - Dennis-Jan Broerse
Advanced PHP: Design Patterns - Dennis-Jan BroerseAdvanced PHP: Design Patterns - Dennis-Jan Broerse
Advanced PHP: Design Patterns - Dennis-Jan Broersedpc
 
New Features PHPUnit 3.3 - Sebastian Bergmann
New Features PHPUnit 3.3 - Sebastian BergmannNew Features PHPUnit 3.3 - Sebastian Bergmann
New Features PHPUnit 3.3 - Sebastian Bergmanndpc
 
PHP 5.3 and PHP 6; a look ahead - Stefan Priebsch
PHP 5.3 and PHP 6; a look ahead - Stefan PriebschPHP 5.3 and PHP 6; a look ahead - Stefan Priebsch
PHP 5.3 and PHP 6; a look ahead - Stefan Priebschdpc
 
Quality Assurance in PHP projects - Sebastian Bergmann
Quality Assurance in PHP projects - Sebastian BergmannQuality Assurance in PHP projects - Sebastian Bergmann
Quality Assurance in PHP projects - Sebastian Bergmanndpc
 
An Infrastructure for Team Development - Gaylord Aulke
An Infrastructure for Team Development - Gaylord AulkeAn Infrastructure for Team Development - Gaylord Aulke
An Infrastructure for Team Development - Gaylord Aulkedpc
 
Enterprise PHP Development - Ivo Jansch
Enterprise PHP Development - Ivo JanschEnterprise PHP Development - Ivo Jansch
Enterprise PHP Development - Ivo Janschdpc
 
DPC2008 Intro - Ivo Jansch
DPC2008 Intro - Ivo JanschDPC2008 Intro - Ivo Jansch
DPC2008 Intro - Ivo Janschdpc
 
DPC 2007 My First Mashup (Cal Evans)
DPC 2007 My First Mashup (Cal Evans)DPC 2007 My First Mashup (Cal Evans)
DPC 2007 My First Mashup (Cal Evans)dpc
 
DPC2007 CodeGear, Delphi For PHP (Pawel Glowacki)
DPC2007 CodeGear, Delphi For PHP (Pawel Glowacki)DPC2007 CodeGear, Delphi For PHP (Pawel Glowacki)
DPC2007 CodeGear, Delphi For PHP (Pawel Glowacki)dpc
 
DPC2007 Objects Of Desire (Kevlin Henney)
DPC2007 Objects Of Desire (Kevlin Henney)DPC2007 Objects Of Desire (Kevlin Henney)
DPC2007 Objects Of Desire (Kevlin Henney)dpc
 
DPC2007 Symfony (Stefan Koopmanschap)
DPC2007 Symfony (Stefan Koopmanschap)DPC2007 Symfony (Stefan Koopmanschap)
DPC2007 Symfony (Stefan Koopmanschap)dpc
 
DPC2007 PHP And Oracle (Kuassi Mensah)
DPC2007 PHP And Oracle (Kuassi Mensah)DPC2007 PHP And Oracle (Kuassi Mensah)
DPC2007 PHP And Oracle (Kuassi Mensah)dpc
 
DPC2007 Case Study Surfnet (Herman Van Dompseler)
DPC2007 Case Study Surfnet (Herman Van Dompseler)DPC2007 Case Study Surfnet (Herman Van Dompseler)
DPC2007 Case Study Surfnet (Herman Van Dompseler)dpc
 
DPC2007 Case Study Zoom & Webwereld (Sander vd Graaf)
DPC2007 Case Study Zoom & Webwereld (Sander vd Graaf)DPC2007 Case Study Zoom & Webwereld (Sander vd Graaf)
DPC2007 Case Study Zoom & Webwereld (Sander vd Graaf)dpc
 
DPC2007 PDO (Lukas Kahwe Smith)
DPC2007 PDO (Lukas Kahwe Smith)DPC2007 PDO (Lukas Kahwe Smith)
DPC2007 PDO (Lukas Kahwe Smith)dpc
 

More from dpc (20)

ezComponents - Derick Rethans
ezComponents - Derick RethansezComponents - Derick Rethans
ezComponents - Derick Rethans
 
Software And The Taste Of Mayo - Marco Tabini
Software And The Taste Of Mayo - Marco TabiniSoftware And The Taste Of Mayo - Marco Tabini
Software And The Taste Of Mayo - Marco Tabini
 
Deployment With Subversion - Lorna Mitchell
Deployment With Subversion - Lorna MitchellDeployment With Subversion - Lorna Mitchell
Deployment With Subversion - Lorna Mitchell
 
State Of PHP - Zeev Suraski
State Of PHP - Zeev SuraskiState Of PHP - Zeev Suraski
State Of PHP - Zeev Suraski
 
Symfony 1.1 - Fabien Potencier
Symfony 1.1 - Fabien PotencierSymfony 1.1 - Fabien Potencier
Symfony 1.1 - Fabien Potencier
 
Advanced PHP: Design Patterns - Dennis-Jan Broerse
Advanced PHP: Design Patterns - Dennis-Jan BroerseAdvanced PHP: Design Patterns - Dennis-Jan Broerse
Advanced PHP: Design Patterns - Dennis-Jan Broerse
 
New Features PHPUnit 3.3 - Sebastian Bergmann
New Features PHPUnit 3.3 - Sebastian BergmannNew Features PHPUnit 3.3 - Sebastian Bergmann
New Features PHPUnit 3.3 - Sebastian Bergmann
 
PHP 5.3 and PHP 6; a look ahead - Stefan Priebsch
PHP 5.3 and PHP 6; a look ahead - Stefan PriebschPHP 5.3 and PHP 6; a look ahead - Stefan Priebsch
PHP 5.3 and PHP 6; a look ahead - Stefan Priebsch
 
Quality Assurance in PHP projects - Sebastian Bergmann
Quality Assurance in PHP projects - Sebastian BergmannQuality Assurance in PHP projects - Sebastian Bergmann
Quality Assurance in PHP projects - Sebastian Bergmann
 
An Infrastructure for Team Development - Gaylord Aulke
An Infrastructure for Team Development - Gaylord AulkeAn Infrastructure for Team Development - Gaylord Aulke
An Infrastructure for Team Development - Gaylord Aulke
 
Enterprise PHP Development - Ivo Jansch
Enterprise PHP Development - Ivo JanschEnterprise PHP Development - Ivo Jansch
Enterprise PHP Development - Ivo Jansch
 
DPC2008 Intro - Ivo Jansch
DPC2008 Intro - Ivo JanschDPC2008 Intro - Ivo Jansch
DPC2008 Intro - Ivo Jansch
 
DPC 2007 My First Mashup (Cal Evans)
DPC 2007 My First Mashup (Cal Evans)DPC 2007 My First Mashup (Cal Evans)
DPC 2007 My First Mashup (Cal Evans)
 
DPC2007 CodeGear, Delphi For PHP (Pawel Glowacki)
DPC2007 CodeGear, Delphi For PHP (Pawel Glowacki)DPC2007 CodeGear, Delphi For PHP (Pawel Glowacki)
DPC2007 CodeGear, Delphi For PHP (Pawel Glowacki)
 
DPC2007 Objects Of Desire (Kevlin Henney)
DPC2007 Objects Of Desire (Kevlin Henney)DPC2007 Objects Of Desire (Kevlin Henney)
DPC2007 Objects Of Desire (Kevlin Henney)
 
DPC2007 Symfony (Stefan Koopmanschap)
DPC2007 Symfony (Stefan Koopmanschap)DPC2007 Symfony (Stefan Koopmanschap)
DPC2007 Symfony (Stefan Koopmanschap)
 
DPC2007 PHP And Oracle (Kuassi Mensah)
DPC2007 PHP And Oracle (Kuassi Mensah)DPC2007 PHP And Oracle (Kuassi Mensah)
DPC2007 PHP And Oracle (Kuassi Mensah)
 
DPC2007 Case Study Surfnet (Herman Van Dompseler)
DPC2007 Case Study Surfnet (Herman Van Dompseler)DPC2007 Case Study Surfnet (Herman Van Dompseler)
DPC2007 Case Study Surfnet (Herman Van Dompseler)
 
DPC2007 Case Study Zoom & Webwereld (Sander vd Graaf)
DPC2007 Case Study Zoom & Webwereld (Sander vd Graaf)DPC2007 Case Study Zoom & Webwereld (Sander vd Graaf)
DPC2007 Case Study Zoom & Webwereld (Sander vd Graaf)
 
DPC2007 PDO (Lukas Kahwe Smith)
DPC2007 PDO (Lukas Kahwe Smith)DPC2007 PDO (Lukas Kahwe Smith)
DPC2007 PDO (Lukas Kahwe Smith)
 

Recently uploaded

Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 

Recently uploaded (20)

Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 

Best Practices with Zend Framework - Matthew Weier O'Phinney

  • 1. Everyday Best Practices for PHP Development Matthew Weier O'Phinney Software Architect, Zend Technologies What you can do to make your life and your team's lives easier. Copyright © 2008, Zend Technologies Inc.
  • 2. What will I gain? • Test your code instead of debug it • Discover issues before you deploy your code • Documentation of your code • Documentation for your users • Better communication with your team • and, bottom line, maintainability. Dutch PHP Conference 14 June 2008 | Page 2
  • 3. The single best practice... TEST! Dutch PHP Conference 14 June 2008 | Page 3
  • 4. Test? • Unit test everything you can • Learn how to do functional and integration testing • Don't put it off Dutch PHP Conference 14 June 2008 | Page 4
  • 5. Benefits of testing • More testing == Less debugging • Revise and exercise your object APIs before writing code • Instant feedback when changes are made • Repeatable • Stabilize functionality • Gain confidence in your application quality • ... Dutch PHP Conference 14 June 2008 | Page 5
  • 6. Benefits of testing • Do you really need more reasons? Dutch PHP Conference 14 June 2008 | Page 6
  • 7. Test behaviors in your models • Example: I should be able to fetch a user by email Dutch PHP Conference 14 June 2008 | Page 7
  • 8. Extend testing to your applications • Given a request to /foo/bar, I should have at least 2 items matching the CSS selector “div#foo legend.bar”: Dutch PHP Conference 14 June 2008 | Page 8
  • 9. Get to know PHPUnit • http://phpunit.de/ Dutch PHP Conference 14 June 2008 | Page 9
  • 10. And another gem: Use a Coding Standard Dutch PHP Conference 14 June 2008 | Page 10
  • 11. Why use coding standards? • Focus on code, not formatting • Consistency • Readability • Collaboration Dutch PHP Conference 14 June 2008 | Page 11
  • 12. Okay, I'll create one... STOP! Dutch PHP Conference 14 June 2008 | Page 12
  • 13. Learn from others • The issues have already been debated to death. • Use an established standard, and stick to it.  Minimizes politics when choosing  Choose a standard compatible with the libraries or frameworks you use  Use the standard as a requirement for hiring or outsourcing. Dutch PHP Conference 14 June 2008 | Page 13
  • 14. What does a standard provide? • File, class, and variable naming conventions • Code formatting conventions Dutch PHP Conference 14 June 2008 | Page 14
  • 15. Some Zend Framework standards • Derived from PEAR standards (which were in turn derived from Horde standards) • One class, one file • Underscores in class names map to directory separators: Zend_Controller_Action: Zend/Controller/Action.php Dutch PHP Conference 14 June 2008 | Page 15
  • 16. Some Zend Framework standards Naming conventions: • Class names are MixedCase • Method names are camelCase • Constants are ALL_CAPS • Properties and variables are camelCase • Private and protected members are _underscorePrefixed Dutch PHP Conference 14 June 2008 | Page 16
  • 17. Some Zend Framework standards Layout Conventions: • No closing ?> tag for files containing only code • Indentation: spaces only, no tabs; 4 spaces per level of indentation • One True Brace:  Classes and methods place opening brace on following line at same indentation.  Logical structures place opening brace on same line.  All control structures use braces, period. • No shell style comments (#) • Keep lines no more than 75-85 characters long Dutch PHP Conference 14 June 2008 | Page 17
  • 18. Example Dutch PHP Conference 14 June 2008 | Page 18
  • 19. What else should you know? Design Patterns Dutch PHP Conference 14 June 2008 | Page 19
  • 20. What are those? • Reusable ideas, not code • Proven solutions to common design problems • Better communication through shared vocabulary Dutch PHP Conference 14 June 2008 | Page 20
  • 21. Some examples, please? • I need to be able to notify other objects when I execute a particular event: Observer • I need to be able to mutate the backend object to which I delegate: Adapter • I need to modify the output of an object: Decorator • I need to decorate my application output with general site content: Two Step View Dutch PHP Conference 14 June 2008 | Page 21
  • 22. Who uses design patterns? • Frameworks; Zend Framework is riddled with them • You do, by using frameworks. :-) Dutch PHP Conference 14 June 2008 | Page 22
  • 23. What next? Documentation Dutch PHP Conference 14 June 2008 | Page 23
  • 24. But I don't have time! • You don't have time to code? Dutch PHP Conference 14 June 2008 | Page 24
  • 25. API documentation is easy • Simply prepend PHP docblocks to your methods and classes; your IDE will often do it for you: Dutch PHP Conference 14 June 2008 | Page 25
  • 26. What can I document this way? • Classes, methods, class properties... • Use annotation tags in source comments to provide context: @param, @return, @throws, @see, @todo Dutch PHP Conference 14 June 2008 | Page 26
  • 27. Docblocks can organize code • Utilize @category, @package, @subpackage; phpDoc uses these to organize documentation. • Prefix your classes; easier to browse, and easier to mix with other libraries. Dutch PHP Conference 14 June 2008 | Page 27
  • 28. Generate pretty API docs • phpDocumentor: http://phpdoc.org/ • Doxygen: http://www.stack.nl/~dimitri/doxygen/ Dutch PHP Conference 14 June 2008 | Page 28
  • 29. See? Dutch PHP Conference 14 June 2008 | Page 29
  • 30. Be careful what you say... • Docblocks can go out of date. Be general, except when it comes to the parameters and return values. • When in doubt, unit tests don't lie. Dutch PHP Conference 14 June 2008 | Page 30
  • 31. IDEs like documentation, too • IDE's introspect DocBlocks to provide typehinting, return values, and method descriptions. Dutch PHP Conference 14 June 2008 | Page 31
  • 32. So does Zend Framework! • Various Server classes utilize DocBlocks to provide hinting for parameter and return value types, as well as method descriptions  Zend_XmlRpc_Server  Zend_Rest_Server  Zend_Json_Server (coming soon!)  Zend_Soap_Wsdl (coming soon!)  Zend_Tool (coming soon!) Dutch PHP Conference 14 June 2008 | Page 32
  • 33. Don't forget your users! • End users like to know how to use your code and applications • Give them a manual! Dutch PHP Conference 14 June 2008 | Page 33
  • 34. XML is not a four-letter word • DocBook is the most common format for open source documentation • DocBook can be compiled to a variety of formats: HTML, Windows Help files (CHM), PDF, and more. • Often used by book publishers (O'Reilly) • It powers the PHP.net manual • It powers Zend Framework's manual Dutch PHP Conference 14 June 2008 | Page 34
  • 35. DocBook is easy Dutch PHP Conference 14 June 2008 | Page 35
  • 36. One possible rendition: Dutch PHP Conference 14 June 2008 | Page 36
  • 37. Don't forget to backup... Source Control Dutch PHP Conference 14 June 2008 | Page 37
  • 38. Why do I need it? • How do I know if somebody did something? • How do others know I did something? • How do I get my updates from others? • How do I push my updates out to others? • Do we have the old version? What changed? Dutch PHP Conference 14 June 2008 | Page 38
  • 39. What are my options? • Distributed Source Control: Developers work on their own repositories and share changesets  Git  Darcs  Arch • Non-Distributed Source Control Developers work on local checkouts, and check in to a central repository  Subversion Dutch PHP Conference 14 June 2008 | Page 39
  • 40. How do I use source control? • Perform local checkout • Write code • Record changes • Check changes in to repository • Check for repository updates • Lather, rinse, repeat Dutch PHP Conference 14 June 2008 | Page 40
  • 41. What do you use? Subversion • Extensible and supported by excellent tools  Write scripts to perform actions before and after checkins • Popular with many open source projects; integrate with them using svn:externals • Easily move files between directories while preserving histories • Simplified process of tagging and branching • Transactions for when things go wrong Dutch PHP Conference 14 June 2008 | Page 41
  • 42. Review Dutch PHP Conference 14 June 2008 | Page 42
  • 43. How do I make my life easier? • TEST! Dutch PHP Conference 14 June 2008 | Page 43
  • 44. How do I make my life easier? • TEST! • Use a coding standard Dutch PHP Conference 14 June 2008 | Page 44
  • 45. How do I make my life easier? • TEST! • Use a coding standard • Learn and utilize design patterns Dutch PHP Conference 14 June 2008 | Page 45
  • 46. How do I make my life easier? • TEST! • Use a coding standard • Learn and utilize design patterns • Document my code Dutch PHP Conference 14 June 2008 | Page 46
  • 47. How do I make my life easier? • TEST! • Use a coding standard • Learn and utilize design patterns • Document my code • Document my application Dutch PHP Conference 14 June 2008 | Page 47
  • 48. How do I make my life easier? • TEST! • Use a coding standard • Learn and utilize design patterns • Document my code • Document my application • Use source control Dutch PHP Conference 14 June 2008 | Page 48
  • 49. So what are you waiting for? Thanks for listening! Copyright © 2008, Zend Technologies Inc.