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?

Update: 8/1/2014

Happy Friday! Just to make sure we’re on the same page, I found an awesome article that pretty much states what I stated. Do not use an out of the box framework for project that require long term maintenance. Build your own with as little abstraction as possible, and only make functions out of code that absolutely repeats itself. No parameters. Read for yourself and decide. Yes, it’s a bit long of a read, but definitely worth it!

https://www.simple-talk.com/content/article.aspx?article=1274

  • 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.

      • Fedor

        Yeah so, there’s cake 3 soon. At least with cake, their philosophy stayed the same through all versions. Simple as hell to learn and use. Symfony, what a nightmare, just when you learn symfony1, there’s symfony2, just when you learn symfony2 they’re already talking about symfony3. I hope they come up with new crazy and stupid shit to learn in symfony3 and have absolutely no backward compatibility, that will make my freakin decade. I love the fact that a site I wrote back in 2007 in pure php took a couple of hours to update some deprecated shit and now it can run on PHP 5.4. Life was so much simpler back then. I like your style George.

    • sodapop7

      luser!
      can’t compare a framework with a language like you compare PHP with C.

  • Here’s a shirt for you ZF haters – https://softwear.co/zf-write-more-do-less-mens-tshirt.html

  • irenkai

    Laravel dudes. It isnt idiosyncratic, works well with composer, works well with teams.
    Symfony is just bloat.

  • Same findings here ! Check my few articles at https://frostydev.wordpress.com (nearly all of them are rants about lack of backward compatibility in PHP frameworks)

  • ZbP

    Great post. Over the years I have find out myself too that rather than framework developer needs just a set of good tools which he can handle well and easy.
    Also it seems to me that ‘very now’ guys have been lately crazed about using as much design patterns as possible and they do prefere code ‘form’ over optimization. Like it is some kind of painting or whatever.
    With this attitude simple things gets complicated as hell, but hey, they are reusable easy to replace and…. You know usual crap..

    Maybe it’s just me beeing old school, remembering times when 128MB RAM at server was ultimate luxury pricey as hell, but I just like when things are fast and smooth…

  • WithheldName

    The author is right. The first time I heard bad things about a framework (it was called “SmartObjects”) was in the mid-1990s. When they released 2.0 several years later, I heard even worse talk about it.

    Every year, there’s another new framework out. Some of them solve serious deficiencies in an underlying language that refuses to advance (like JQuery does for JavaScript) and become hits. Some find special niches, like Magento for e-commerce, and build a following. But the other 95% become trendy trash that nobody touches within a few years.

    They all suffer from the same issues: too many of them, none is standard, they’re incompatible with underlying language upgrades, they do too much, intrude too much, and have too many limitations. Everything the author says is true. It’s what most experienced developers know. But few people come right out and say it because it’s all about the money for most folks.

  • But I think Laravel is the best one.

  • sodapop7

    amen