PHP Best Practices
PHP Best Practices
14 June 2008
| Page 2
TEST!
14 June 2008
| Page 3
Test?
Unit test everything you can Learn how to do functional and integration testing Don't put it off
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 ...
14 June 2008
| Page 5
Benefits of testing
Do you really need more reasons?
14 June 2008
| Page 6
14 June 2008
| Page 7
14 June 2008
| Page 8
14 June 2008
| Page 9
14 June 2008
| Page 11
STOP!
14 June 2008
| Page 12
14 June 2008
| Page 13
14 June 2008
| Page 14
14 June 2008
| Page 15
14 June 2008
| Page 16
No shell style comments (#) Keep lines no more than 75-85 characters long
Dutch PHP Conference 14 June 2008
| Page 17
Example
14 June 2008
| Page 18
Design Patterns
14 June 2008
| Page 19
14 June 2008
| Page 20
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
14 June 2008
| Page 21
14 June 2008
| Page 22
What next?
Documentation
14 June 2008
| Page 23
14 June 2008
| Page 24
14 June 2008
| Page 25
14 June 2008
| Page 26
phpDoc uses these to organize documentation. Prefix your classes; easier to browse, and easier to mix with other libraries.
14 June 2008
| Page 27
http://phpdoc.org/
Doxygen: http://www.stack.nl/~dimitri/doxygen/
14 June 2008
| Page 28
See?
14 June 2008
| Page 29
14 June 2008
| Page 30
14 June 2008
| Page 31
14 June 2008
| Page 32
14 June 2008
| Page 33
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
14 June 2008
| Page 34
DocBook is easy
14 June 2008
| Page 35
14 June 2008
| Page 36
Source Control
14 June 2008
| Page 37
14 June 2008
| Page 38
14 June 2008
| Page 39
14 June 2008
| Page 40
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
14 June 2008
| Page 41
Review
14 June 2008
| Page 42
14 June 2008
| Page 43
14 June 2008
| Page 44
14 June 2008
| Page 45
14 June 2008
| Page 46
14 June 2008
| Page 47
14 June 2008
| Page 48