Views
Pros and Cons of PHP
From Shadowfax
PHP is my language of choice for website development. It is also widely adopted and widely-used across the web. However, it is not without its problems.
Contents |
PHP has evolved rather than grown
You see this throughout PHP. Where most programming languages have a small core and add additional functions through libraries, the PHP core is vast.
- There are multiple functions to achieve similar things
- Naming of functions is inconsistent
- Parameter order of functions is inconsistent
- PHP's inherent scoping mechanisms are unusual
Despite all of this, PHP remains one of the easiest languages to learn. Not least because PHP's online documentation is comprehensive, easy to navigate and peppered with examples.
As an aside - I read recently someone saying that PHP was poorly documented. I'm not entirely sure what they meant. The online PHP manual is a great resource. Firstly it is all there, all hyperlinked and all searchable. Secondly (and this for me is the real advantage) it is crammed with real-life examples. Adobe's Flex (probably my second favourite language at present!) by contrast has a much higher quality of software engineer written documentation but almost no examples. And that's the kicker. Examples seperate good documentation from great documentation. Once you know a language you don't need the examples any more - but then, you need the manual much less too. For learning language good examples beat good manuals every time for me.
Poor separation of presentation from content and business logic
PHP was originally designed as a templating language. Despite that it is very easy for the novice coder to embed presentation so heavily in the code that it becomes very difficult to extract later.
Having said that, with discipline and use of good object-orientation principles it is also very easy to code PHP with separation built in. To start with there are a number of PHP templating engines for example Smarty, Tiny But Strong and PHP Template. These can help - although in the case of Smarty at least you end up having to learn another language and using that to code in the template - which somewhat defeats the purpose in my view. Another solution is to use PHP as the templating language and just be massively disciplined about keeping the template files purely about layout and excluding any layout in the logic.
Easy to code very badly
This is a continuation of the previous line of thought. PHP lets you code any way you like. It does nothing to enforce good practice. This allows novice programmers to develop very quickly - but it can leads rapidly to unmaintainable code. Here again there is no substitute for discipline.
No built in name-space
This is one of the biggest cries of the PHP critic. There is no name spacing in PHP which means that it is very easy to declare the two functions with the same name. This can be a big deal on larger projects. However, with the application of object-orientation it is very easy to ensure that all utility functions are declared in utility objects and this vastly reduces the issue.
PHP is not thread-safe
This one is less easy to deal with. Without caching PHP is inherently slow. It also is not thread-safe which means that it resists scaling to larger applications. Hopefully this will be fixed soon. It is a definite concern for larger projects.
Final Thoughts
No programming language I have ever worked with has been perfect. They have all had their share of issues. From a conventional software engineering perspective PHP probably has more issues than the mainstream designed languages. Despite that, however, I still love PHP. I find it infinately less frustrating than Perl, more forgiving than C and easier to learn than, um... well than anything else. For small to medium-sized web projects it is faster to learn and faster to deploy than most other languages.
I would never use PHP to build big, integrated systems. For building a web-site and adding lots of widgets to the edge of it I'd use PHP every time.
Leave your comment