All PHP Frameworks Suck… Except for Mine

The thing about frameworks is that they’re built by developers to meet an out of the box solution. Sometimes, that’s a complicated piece of spaghetti code that can be used for anything, such as Zend 2, and sometimes, it can be a simple scaffolding set up in a very opened Core PHP way such as Yii, but still has the tread marks of included files and unnecessary nested functions, with an abstracted database layer.

The problem I’m having with any out of the box framework is this… Well, there are several problems.

1. Layer of abstraction for database.

I’ve heard this so many times before. What if the database changes? it’s easier to change that layer of abstraction than to go through your whole site and change the sql statements.

The problem I have with this is again, lazy developers will always make things worse for the rest of us. What you don’t realize is that by being lazy, you’re destroying your performance. Let me explain.

Typical mysqli statement:

1
2
3
4
5
6
7
8
$sql_i = "SELECT name FROM table WHERE id = ?";
$dbi = mysqli_connect(...
$stmt = $dbi->prepare($sql_i);
$stmt->bind_param("i",$id);
$stmt->execute();
$stmt->bind_result($name);

echo $name;

Ok, still a few functions to run through. Not bad though when you compare with how Yii, or Zend 2 propel queries for the same data. let me explain.

1
$query->select('table')->where('id',$id);

Yes, it looks smaller, but you’ve just added at least another object, and two more function calls. This is in addition to the back end mysql calls that happen to actually get that data. As far as micro optimization goes, this sucks. You’re not just adding two more function calls and an object; you’re adding an object and two function calls for EVERY QUERY that you run against the database.

In one of my previous work places, the lead developer was so obsessed with micro optimization that he would create arrays that would be build with brackets instead of array_push(). Obviously, the function call is more expensive when it comes to micro optimization. So, it’s ok to not be optimized when it comes to database calls only?

Then, they were wondering why their website loads at over 4 seconds. They had over 100 http request calls. No website should have over 25 calls, I don’t care how complicated your business logic. In the end, that’s what matters. Site speed is mostly determined by the amount of http requests. The problem was that with the framework they were using, it would have been nearly impossible to refactor the site to allow for concatenation of css and js files without writing it in Core PHP. What’s the point of this framework? Which brings me to my second point.

2. No flexibility for custom code

No matter how robust a framework is, it will always have constraints. There are limits to the things you can do with it. Symfony 2 for example, only allows for either sessions or cookies to be set in one call. Sessions are overwritten by cookies. So, in the end, we ended up writing Core PHP to handle both being set. Explain to me exactly what the win was there. If we’re going to avoid the framework and not use the framework’s internal functions, what’s the point of using the framework? Only to have it as a “cool” layer of abstraction? Because you think you’re cool that you know the framework?

Updates

Whenever PHP had an update, it was still PHP. New functions that would allow for more things to be done, and deprecated functions slowly making their way out. Slowly. You could still run your old code on the new PHP platform. You didn’t have to change anything, unless you wanted to optimize some of your code.

Have you ever tried upgrading from Zend to Zend 2? Symfony to Symfony 2? A freakin’ nightmare. And what’s ever worse is that with any new update to PHP, you couldn’t take advantage of this new version inside your framework. So, now you’re stuck using an older version of PHP, and a never changing framework, until the new version comes out, not having the guarantee that the new version of your framework will work with your old code.

When PHP updates, it has been usually tested by many more developers than if Yii updates. There’s a larger support group that will help you understand this new functionality. When a framework updates, the only ones that fully understand the framework are the developers of that framework. You have to pick up from the beginning and re-learn it. Sometimes this can take months. And once it’s perfected, a new version comes out. How is this progressive towards development?

PHP on its own is a framework. A much more robust, and opened framework. It will allow you to do whatever you want.

In conclusion, my theory holds true about frameworks. The best framework is the one you build from the ground up. I keep saying the same thing over and over:

“It’s not the tools you use, it’s how you use them”.

Thoughts?

  • dominus domino

    n00b!

    PHP, or the framework as you like to think of it, is nothing more than a wrapper for C. Why are you wasting all of that function overhead and not just writing code in C?!! Actually, C is nothing more than overhead for a generic compiler to write Assembly of which you can optimize and then turn that into an object file. Frankly, if you aren’t using magnets to control electrons through logic gates, then you’re just lazy! ;)

    • George

      Excuse me for not liking the overhead of crappy written frameworks that can’t adapt from version 1 to 2, or 2 to 3. Excuse me for being PHP developer who can handle PHP just fine as is, and can’t wrap my head around confusing and badly written spaghetti code that limits your development skills. If frameworks were so awesome, why Cake 2.0? Why Symfony2? Why Zend 2? Why anything 2.0? Why Yii 2.0? Why all the 2.0s? And why aren’t they compatible with all of the 1.0 versions? I’ll tell you why… Because of all of the true noobs that see something new out of college and think it’s the best thing ever because they can now be lazy. That’s why. Lazy ass developers looking for shortcuts. And it only took Yii 6 years to get to v 2.0. PHP is ever evolving and won’t crash your site if you upgrade to it. In fact, you get performance boosts and code that actually runs well. Of course, this depends on how well you wrote it in the first place. But with frameworks? You’re stuck. Most older frameworks you can’t even use OOP PHP. You’re stuck. Unless you re-write the whole project. But what will you re-write it in? Yii 2.0 which is now in beta? Come on. Stop being lazy, take your time, create proper form validators, cross site scripting prevention, etc. There are plenty of tutorials on how to do that even for noobs like me. No one wants to do the work anymore. Of course, why would they? In two years they will move on to other companies, and ruin their technology department. The old company is now stuck to hire someone that’s an expert in an outdated framework. If your site was built on PHP, you’d have a MUCH better chance of hiring good developers. Anyway, Good luck!

      Oh, and why not C? Or assembly? Because I know PHP. PHP can run on any windows / linux system (macs included). That’s 99% of machines out there. Talk about rapid development time. You have WAMP, MAMP, XAMPP, etc, etc… and the good ol LAMP that you can install easily on a linux box command line server.

      That’s why.