10 Principals of PHP DevelopmentBy Binny V A • Sep 11th, 2008 • Category: PHP, Web Development
Are you a PHP developer? Go read the article ‘10 Principles of the PHP Masters‘. Do you want to learn PHP? Go read it.
With PHP’s widespread adoption,it’s almost too easy to find a script or snippet to do exactly what you need. Unfortunately, there’s no filter as to what is a “good practice” and what’s, well… not so good when writing a PHP script. We need trustworthy sources, who have proven they have a solid grasp on the best practices of PHP.
Use PHP Only When You Need it
PHP was designed for Web Development – and its very good at it. Just because you can use it to create desktop apps don’t mean that you have to.
Use Many Tables With PHP and MYSQL for Scalability
This advice comes from a rather controversial database design choice he made when creating WordPress MU. It created separate tables for each blog rather than the usual method.
Never, ever trust your users
Validate everything that comes from the user. Yeah, I know its boring – but it must be done.
Invest in PHP Caching
Caching is very important if you have a busy site.
Speed up PHP Development with an IDE, Templates and Snippets
I find it a bit hard to support this. Yeah IDEs speed up development – a small bit. About Snippets – use them if you trust the source.
But if you really want to speed up development,
- Use a framework(coming up later)
- Invest in code generation.
Make Better Use of PHP’s Filter Functions
This is actually new to me – but I am going to try this out.
Filtering data. We all have to do it. Most, if not all of us, despise doing it. However, unbeknown to most are PHP’s filter_* functions, that allow us to do all sorts of filtering and validation. Using PHP’s filter_* functions, we can validate and sanitize data types, URLs, e-mail addresses, IP addresses, strip bad characters, and more, all with relative ease.
Use a PHP Framework
This is one thing that really speed up development. Also, the programmers that have to maintain your programs will thank you for it.
Don’t use a PHP Framework
The basic argument is that Frameworks slow things down. Keep that in mind when your choosing a framework.
Use Batch Processing
Jack D. Herrington
This refers to the tasks that can processed in the background – Herrington recommends using batch processing and cron here. As most of you are aware, PHP don’t have threads – and it don’t matter to me. You don’t use threads when serving a web page. But in cases like these, threads come in handy.
My advice? Use Python or some other language that has threads to do do the job for you – you don’t have to do everything in PHP.
Turn on Error Reporting Immediately
This is very important when developing the app – error reporting lets you find future bugs. Make sure they are on.
And just as important is the fact that you should turn them off in the production system – you don’t want your users seeing your error messages.