What are the best PHP Frameworks in 2018? Symfony? Laravel? Or else ?? Let’s compare those two!

In this post, I will try to compare most popular PHP frameworks. I know that writing posts like this could be like putting a stick in an anthill, but I will do my best to be fair for both sides

When you start to learn PHP or are deciding about technology stacks for new project, sooner or later you have to make a decision and choose a right PHP framework.

The decision could be really hard because of multiple possibilities. Choosing the right framework could be crucial for your project but also for your PHP learning journey.

The Possibilities

Let’s start from the possibilities. In the last of couple years, when you ask programmers about PHP frameworks, the standard answer was always Symfony. Most modern open source software was also rewritten to use more or fewer features from Symfony frameworks. But in last two years, we can observe the growing popularity of Laravel framework.

What are the other options? Well, let’s focus only on those most popular ones. Besides Symfony and Laravel, we can also use Codeigniter, Zend, CakePHP, YII, Phalcon and more..

Let’s see how popularity has changed in the last two years:

Source: https://trends.google.com/trends/explore?q=laravel,zend,codeigniter,symfony,cakephp

From this chart, we can see that there was Laravel and for a long long time, nothing.

On the second place is almost exactly Symfony and Codeigniter.

Let’s look also at the number of questions regarding those frameworks on Stack Overflow:

I am a fan of Symfony, however, I can understand the growing popularity of Laravel Frameworks. For the purpose of this article, I will focus myself on those two frameworks only.

In my next article, I will compare other PHP frameworks.

It’s all about complexity!

When you start to learn PHP and you get to the moment when it’s time to learn first framework, Laravel will be the better choice for you. Why? Because it’s very simple to learn.

Symfony is waaaay more complicated. But when you are an experienced programmer and about to choose technology for a new project, then your decision could be different.

If you are skilled at PHP PRO, then you simply know that Symfony rocks! The possibilities of customization are unlimited. Let’s compare this to real life.

Using Laravel is like buying a laptop, and using Symfony is like building a PC from scratch, deciding what parts and components to use. Symfony is way more complexed and perhaps harder to learn. When you master it, you can see it’s also way more flexible.

But is it always the best framework to use?

It all depends on the project..

When you have small projects, or are in the first phase of, for example, a startup product, Laravel could be better choice for you. It provides a simple app that you can grow very rapidly. Also, many programmers know Laravel very well so it’s going to be easier to scale the project and provide more developers.

But if you are working on a more advanced project, Symfony is the best choice you can make. It’s fast, flexible, expandable, stable, and sustainable. Like with Laravel, there are a lot of programmers who know Symfony and, also, there’s a huge library of bundles and documentations available online.

Let’s compare!

There’s one more fact I must point out. Laravel was built on Symfony. Yes, core components like routing, HTTP, sessions and etc. are used from Symfony:

Laravel constructors take what’s bests from Symfony and make it simplier and more rapid to use.

Pro’s and Con’s

Laravel Pro’s:

  • Rapid development
  • Simple file and code organization
  • Great documentation
  • ORM
  • Unit testing
  • Many built in functionality
  • Artisan – great Command Line Interface
  • Solid encryption
  • Proper cache with good cleaning

Laravel Con’s:

  • Too much queries to DB
  • Problems with working on shared hostings
  • Sometimes it’s just slower than other frameworks

Symfony Pro’s:

  • Performance, performance, performance!! (in most recent versions using PHP7!)
  • Flexibility
  • Lots of bundles, packages, commercial third party software, documentations etc.
  • ORM
  • Unit testing
  • Many extension projects for CMS like EasyAdmin, SonataProject etc.
  • Symfony profiler – great tool

Symfony Con’s:

  • Complex documentation
  • Many differences between maintained versions
  • Steep learning curve

Differences in code

Now, let me show you some sample codes in Symfony and Laravel doing the same, so you can decide what suits you best.

For my examples, I will be using mostly Symfony in version 3.4. There are some differences in Symfony 4.

  1. Installation!

    In Symfony 4, you may install projects through composer. Simply use:

composer create-project symfony/website-skeleton my-project

But in the previous version of Symfony, you need to do more:

sudo mkdir -p /usr/local/bin
sudo curl -LsS https://symfony.com/installer -o /usr/local/bin/symfony
sudo chmod a+x /usr/local/bin/symfony

In Laravel, it is as simply as in Symfony 4:

composer global require "laravel/installer"
laravel new laravel_project
  1. Configuration

The first thing you will probably edit after the installing project is the configuration. In Symfony, there are many configuration files but the most important is in app/config/config.yml . Symfony allows you also to create different configurations for every environment by simply using config_ENV.yml file.

Standard configuration in Symfony 3.4:

# app/config/config.yml
    - { resource: parameters.yml }
    - { resource: security.yml }
    - { resource: services.yml }

    secret:          '%secret%'
    router:          { resource: '%kernel.project_dir%/app/config/routing.yml' }
    # ...

# Twig Configuration
    debug:            '%kernel.debug%'
    strict_variables: '%kernel.debug%'

# ...

In Laravel, you have a file with keys and values .env and a app.php file with standard PHP configuration.

Standard Laravel .env file:







Standard Laravel app.php file:

    'env'      => env('APP_ENV', 'production'),
    'debug'    => env('APP_DEBUG', false),
    'url'      => env('APP_URL', 'http://localhost'),
    'timezone' => 'UTC',
    'locale'   => 'en',
    'key' => env('APP_KEY'),
    'providers' => [
    // …
    'aliases' => [
    // …
// …

For me, Symfony’s YAML is more readable. However, if you don’t know YAML, then in Laravel, you can live with that

  1. Routing

In Symfony, we mostly define routing by YAML annotations in controller. Example in Symfony 4:

// src/Controller/BlogController.php
namespace AppController;

use SymfonyBundleFrameworkBundleControllerController;
use SymfonyComponentRoutingAnnotationRoute;

class TasksController extends Controller
     * Matches /tasks exactly
     * @Route("/tasks", name="tasks_list")
    public function list()
        // ...

     * Matches /tasks/*
     * @Route("/tasks/{slug}", name="task_show")
    public function show($slug)
        // $slug will equal the dynamic part of the URL
        // e.g. at /tasks/task1, then $slug='task1'

        // ...

In Laravel, we have default route files. That’s the place where we define some routes. For example:

Route::get('/', function () {
    return view('welcome', [
        'name' => 'Michal'

Route::get('/about', function() {
    return view('about');

Route::get('/tasks', function() {

    $tasksDB = Task::all();

    return view('tasks.index', compact('tasks', 'tasksDB'));

As again, you may have noticed that Laravel’s routing is in one file and it may be easier (especially for smaller projects).

  1. Templates

Symfony uses Twig templates. It’s a very good templating language where you can code front-end in readable templates that are more friendly to front-end developers, etc. Front-end developers may code templates in TWIG without knowledge of PHP.

Little example:

        Welcome to Symfony!

{{ page_title }}

In Laravel, we have a PHP based blade templating system. Again, if you know PHP, you don’t have to know Twig, but if you are a front-end developer, you need to have some PHP background to code templates in Blade.

Example below:

getLocale() }}">



Which framework is better?

Personally, I think that there is no straight answer to this question. If you are working in Symfony, and you think that it’s a lot better than Laravel or another way, and you are an experienced Laravel developer and you always saysthat Symfony sucks, then all I can say is that you did not understand the framework you’re complaining about.

Both frameworks are great – all you need is to know which one will be better for your current project.

So what framework should you use?

In my opinion, you should pick the framework based on the project specification rather than the popularity of the framework.

As a programmer, I’ve working with Symfony for over five years. Since year one, I’m using also Laravel and I see the pros and cons in both of those frameworks.

The decision is up to you. I recommend you to get familiar with both of them. Then, do some projects using Laravel and some other projects using Symfony. Only experience can give you enough knowledge to choose what framework will be best for your next project.

Looking on global trends, I guess that if you want to call yourself a professional back-end developer, you need to know at least those two frameworks.

Codementor Tutorials责编内容来自:Codementor Tutorials (源链) | 更多关于

本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » 综合编程 » What are the best PHP Frameworks in 2018? Symfony? Laravel? Or else ?? Let’s compare those two!

喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录