Home » PHP » Yii and Zend for PHP = ASP.NET and ASP.NET MVC for C#

Yii and Zend for PHP = ASP.NET and ASP.NET MVC for C#

January 25th, 2011 Leave a comment Go to comments

In the past I have extensively used ASP.NET and ASP.NET MVC in C#.  In C# they are basically the only options and it would be rather crazy to try to come up with your own high-level web framework on top of C# and rightfully so.  However when I moved over to be doing a lot of web development in PHP (see PHP for ASP.NET Developers which I blogged about before) things were not so rosy.  PHP is a great scripting language, many things are very simple to do and well geared towards web development.  However, a bad (and a good in some way) thing about PHP is that it’s a very low level language and doesn’t provide many of the higher-level framework nicities that is provided with ASP.NET and ASP.NET MVC straight out of the box.  By nicities I mean things like structured request routing and handling (with hooks/events), page lifecycle, MVC separation, configuration management (e.g. web.config), logging and so on.  It is also a fact that many PHP developers and participants in open-source projects are not professional programmers with an IT or software engineering degree.  What all of this has lead to is A LOT OF HORRIBLE ARCHITECTURE AND CODE.  Having looked through the source code of many many open source PHP projects, there is only a very very small handful that I would say are very well architected.  In some cases there is no architecture at all, in other cases there is some attempt at architecture but it’s not particularly good and in other cases things are over-architected to the point that making even a small change, let alone a complex change becomes extremely difficult.  For many users of these open-source projects this of course doesn’t matter as they don’t ever have to look at the code, but for anyone looking to make serious changes this is quite a problem indeed.  The best architected open-source applications I’ve seen are OpenCart (has it’s architectural flaws, but not too bad), being a Shopping Cart application, and Drupal (being a CMS).  Some people may say Drupal is not well architected because it’s not PHP5 Object Oriented code, but I don’t think you need to have PHP5 or OO for an application be well architected.  For example in C you can structure your application well, or you can structure it poorly and same goes for PHP.  You don’t have to use the latest technology to structure it well.  Sure there are obviously certain performance factors that come into play when you have load lots and lots of modules just to see if they’re enabled, but such is life when you’re building a configurable system.  Other applications in those classes of applications are not very well architected at all.  Here’s a non-exhaustive list:
Shopping Carts

  • PrestaShop – Pretty ugly architecture, poor file structure, doesn’t use MVC (poor form for a modern application), un-necessary use of Smarty for templating, all the admin code output using echoing directly out of modules instead of using MVC pattern, etc.
  • osCommerce – No programming standards, mix of code and markup, terrible code re-use, and just plain ugly bad design.
  • ZenCart – TERRIBLE design rooted in osCommerce that’s almost impossible to change if you try to make serious modifications as you have to change way too many files.
  • Magento – Over-architected to the point of obscrurity (not unexpected given it is based on Zend Framework) which impacts performance and requires lots and lots of caching.
  • Commercial Carts – This includes CSCart, X-Cart, etc – There is some attempt at decent architecture but often it still comes up short.

CMS / Blogs

  • Joomla – Over-architected MVC design and terrible rigid structure and security model.
  • WordPress – Horrible mix of PHP and HTML, although workable to some degree, it is far from well architected.
  • ModX – Ok-ish architecture but also rather ugly when you look at the code.

Now when it comes to frameworks, which is more the subject of this post, things don’t change much.  Most of the frameworks are also poorly designed and structured with their design patterns firmly rooted in PHP4.  This includes CodeIgniter, Kohana, DooPHP and pretty much every other framework I’ve looked at with the exception of Yii and Zend and perhaps Symfony and a few others (see Choosing the Best PHP Framework).  Ultimately after much research I’ve found Yii and Zend to be by far the best structured (with Zend over-engineered).  What I have found is that Yii Framework is by far the closest thing there is to .NET so I’m finding that any application that I’m looking to write even if it’s a console application is well handled by Yii, even if it’s because it has a decent architecture (which I can’t fault).  I’m finding that even for little PHP scripts without a user interface and simple web applications it’s easier and better for me to use Yii Framework even just because of the database access and configuration capabilities that it provides and of course the structured design.  I do find that it is still lacking a few things that are general framework classes (e.g. HttpClient, Application File System) rather than anything specific to do with web development).

Share
Categories: PHP Tags:
  1. Gaurav
    August 10th, 2011 at 09:19 | #1

    Great post. Even though I’m not an IT/Comp engineer myself, I’ve learned my programming from some highly qualified sources. Architecture, as you mentioned, has to be extremely important. Sometimes, I really wonder how do these open source application guys maintain their code, especially when it’s so jaggedy. You should really write a blog on, for example, ‘the ideal code architecture design’ and what makes perfect frameworks perfect.

  2. hjoab
    September 4th, 2012 at 12:34 | #2

    Thanks for this post. yeah you can go on deeper into the research and tell us all about it.

  1. No trackbacks yet.


nine − = 4