What is the best PHP framework for web development?

The debate about using or not using frameworks; if we should use one which one is the best is been around for a very long time in various development communities. I am probably going to raise the same debate too through this post, even though my first intention is to avoid that.

I am driven by two main reasons to write about this topic. The first reason is a comment on one of my post on LinkedIn, and the second is this post on Facebook entitled: What if I told you frameworks make you a terrible programmer.

Many people around the world have these three problems:

1. Never re-invent the wheel

This is a true and normal behavior of human beings.

The first aspect is always making lazy people lazier and the hardworking ones feel insecure. But, no wheel is permanent and immortal. If no one has a deep understanding of how wheels are made, how could they make more or maintain the existing ones? Learning the raw aspect of a programming language is to secure that position. Rasmus Lerdorf and his peers could've stopped developing PHP since version 3 or 4 and used the Zend framework and life goes on. Is that what you mean? Do you know how many core programmers are behind a programming language? Reconsider your thoughts about this idea. Always re-invent the wheel. We wouldn't have left the stone age to this new world we're in today.

There are cases where frameworks are not appropriate. How do you do, Do you reinvent your own framework, or do you go for a raw code? This is not to say frameworks are not necessary. They are of course. But they're meant for specific reasons and needs. So, comparing using a framework or going raw is a big mistake. They are two different perspectives and initiatives. In that I like Matthias Kaschubowski's' comment:

Don't evangelize "do not use frameworks", do evangelize "understand what you use, if not, don't use it".

Frameworks are meant to be used as I said. Besides, they don't create things for you. You still have to go raw and get your job done. That's why I usually ask myself how do people manage to use a framework without knowing the fundamentals of a language. I consider that before you can use any framework efficiently, you should be proficient in its core programming language. Then, you use a framework to learn from the experts, give some robustness to your application, ensure its security, etc.

What has to be learned in frameworks is beyond coding basics. It's coding practices.

2. Which framework is the best?

If I was to ask such question to myself or to anyone else, I should be in front of a project I have already planned and know exactly what is needed. And I have decided to go for a framework, not coding from scratch.

A framework is best for a use case(a project) not to other frameworks.

You know it's not about the framework's power but your own power. I don't believe a framework is necessarily better than the others, especially in the PHP community where I know much. Frameworks have their characteristics and philosophy. Based on your level of understanding of the core programming language, you might find one more/less interesting.

It's not the framework itself, but the programmer.

Most people go to Laravel not because it does things other frameworks can't do, but because of its philosophy. This is applied to any other framework.

We have different types of frameworks. We have micro-frameworks like slim, fatfree, lumen, etc. Component-based high-performance like yii. Application Development Frameworks like CodeIgnator, and so on.

If I had to undertake a project which requires a whole bunch of tools I would go for a full-featured framework like Laravel. If I had to worry about maintenance and security more, I would go for Symfony. It's a matter of need. Sometimes you don't even have a choice than using a framework or a component of it.

Also, the other aspect is the coding style. When you are advanced in coding. It comes a time where you worry more about how your code is designed than it works or not. Therefore, programmers also look at how a framework treats code. Let's look at the following examples of routing in various frameworks:

Slim framework

$app->get('/', function($request, $response, $args){
    return $response-.write('Hello World');
});

Laravel

$app::get('/', function(){
    return 'Hello World';
});

Symfony

$collection = new RouteCollection();
$collection->add('blog_show', new Route('/blog/{slug}', array(
    '_controller' => 'AppBundle:Blog:show',
)));

return $collection;

FatFree

$f3->route('GET /',
    function() {
        echo 'Hello World';
    }
);

Yii

use yiihelpersUrl;

// creates a URL to a route: /index.php?r=post%2Findex
echo Url::to(['post/index']);

From here you can see that the code taste can be very important.

3. Aspect into consideration while choosing a framework

When making a choice of framework, there few things one could consider:

  • Your project requirements
  • Framework Philosophy
  • Robustness
  • Documentation
  • Community & Help
  • Deployment
  • Consistency
  • Is the code development team active
  • Testability
  • Requirement(server resources)
  • Templating
  • Dependencies
  • Extend-ability
  • License
  • Database abstraction

Bottom Line

Do not get trapped by supremacy. Do what you do best. Do not choose a framework based on what people say about it, rather it's should be based on your project requirement.

Of course, this is based on my own experience. But I hope it gives one or two ideas. Let me know what you also think about the subject.

If you loved this post, please share it with your friends. It helps promote the website.

Thanks for reading.