Symfony vs Laravel: Which PHP Framework to Choose?

Symfony vs Laravel: Which PHP Framework to Choose?

Umbrella IT

Anyone being this or that way related to PHP web development has definitely heard about these two frameworks.

Symfony and Laravel are much-and-often talked about, and, mostly, in a good way. So, what is the right way, to choose the best out of good? This is the topic of new Umbrella IT article.

Why have we decided to speak today about Laravel vs Symfony comparison?

ON THE ONE HAND,

currently, all PHP frameworks are in high demand. This can be explained by the fact, that PHP programming language has been enjoying significant popularity with the development environment within the previous few years.

PHP (Hypertext Preprocessor , originally Personal Home Page Tools), is a language that started as a set of tools aimed to develop personal web pages. And today it is still acknowledged as the tool, mostly used by many developers to build interactive and user-friendly web apps.

Source

As you see from the diagram above, PHP occupies the stable leading position as the language, most frequently used by sites, and is successfully applied for creating high-load sites.

PHP was used to build such famous projects as:

  • Wikipedia
  • Baidu
  • Yahoo!
  • Tumblr

ON THE OTHER HAND,

both Laravel and Symfony are intended to accelerate development and ensure good performance. In this context, each of them offers its own approach and possibilities to the developer.

From this standpoint, Symfony PHP framework appears to be some stability pillar.

Throughout its existence, Symfony 2 has turned into a kind of classic decency in PHP development. The framework has gained the high stability level and continues improving.

Meanwhile, Laravel is a fairly young framework that is actively developing now. Its creators have chosen a different approach and followed a new path.

HOWEVER…

The start was taken from Symfony.

Laravel is created on its basis and inherited much from its predecessor.

Symfony is, in general, distinguished by being composed of various components. The components can be added and replaced or can be used in projects created with the frameworks other than Symfony.

Many of the components, initially designed for Symfony, are used in Laravel, which anyway does not mean it to be a copy of Symfony.

FRAMEWORKS SPECIFIC FEATURES

  • INSTALLATION

To install the framework we need to load Symfony Installer. For this purpose the following command shall be performed in any appropriate console application:

$ sudo curl -LsS https://symfony.com/installer -o /usr/local/bin/symfony

Console application is an application that allows interacting with the computer using text commands (instead of graphic interface, the user got used to).

As soon as the components installation is complete, we create new Symfony app using the following command:

$ symfony new my_project_name

Laravel installation is the same. The installer is loaded with the dependency manager for PHP - composer. For this purpose, perform the following commands in the console application:

$ composer global require "laravel/installer"
$ laravel new my_project_name

This means that in both cases the developers took care to ensure, that installation and start of the framework will not require much time, and we can get a ready-to-use set of tools with a minimum effort.

  • CONFIGURATION

Symfony supports a wider set of formats: PHP, YAML and XML. The possibility is available, to choose either the most appropriate for the given project (for example, XML is used as standard by many major companies) or the one preferred by the developer according to his/her experience and qualification.

Laravel supports one format only - PHP. This excludes any choice issue. But, in general, this format is sufficient, especially for the beginner-developers. They do not need to learn any other formats, but for PHP.

  • HTTP FUNDAMENTALS

Function of any app presents the following process:

  • receipt of HTTP request by the server from the client (The user fills in the form on the site and clicks SEND button);
  • handling the request by the server;
  • responding to the request (The user sees the message: “You have successfully registered!”).

Any request to the server shall be first checked for conformity  to various rules (whether the user has access to the information requested, what data format is sent, etc.)

For example,

You want to read more detailed information on the page and click See details…, this means you send the request to go to the more detailed content.

And in case the access to the content is allowed to the authorized users only, the request will be denied, and you will be redirected to the authorization/registration page.

For this purpose, Laravel uses middlewares - levels of verification to be passed by HTTP request on the way to an app. All requests to your app are checked against certain criteria. If they fail to pass, they are rejected.

In Symfony the similar process runs using kernel events method. The events to be sent to the app are considered. And these events can be limited using filters.

From the technical point of view (at the code level) the approaches differ, but in both frameworks, the process is provided for in the original functionality. It should be noted, that the inexperienced developer will probably find Laravel approach easier to be implemented.  

Zumic -  built using Laravel

  • TEMPLATE ENGINE

As a template engine (required to process HTML templates to create ready-made HTML pages), Symfony uses Twig by default, while Laravel applies Blade.

Both template engines do offer the required features:

  • templates inheritance: this excludes the need to create codes  repeatedly and allows developing flexible structure;
  • control structures: allow identifying the code blocks;
  • escaping the default output: prevents eventual XSS attacks.

The difference is that Twig possesses more rigid structure and does not provide for inserting PHP code directly into the template. At the same time, it allows using filters.

From this point of view, Blade is more flexible. It makes possible to write the code in the template, and it can be easily and endlessly extended.

  • DATABASES

Both frameworks offer fresh solutions for easy databases handling, not directly, but through the abstraction layer.

Due to this, the following is possible:

  • easy data handling in the app;
  • switching between DBMSs (Database-Management Systems) practically without any code changes (for example: switch from mysql to postgresql);
  • decreasing the rate of the developer’s errors when handling databases.

For this purpose Symfony applies the third-party solution - Doctrine set, while Laravel possesses its own Eloquent library.

Their difference is as follows:

  • Symfony applies a more advanced pattern to process the data, which is also more complicated. The programmer interacts with the databases through Doctrine (Object-Relational Mapping). The process is based on the abstraction layer described above. Some definite time has to be devoted to learn Doctrine, prior to starting using it.
  • For the same purposes, Laravel uses its own Eloquent library. The library is included with Laravel and presents more simple and intuitive solution.

BlaBlaCar - built using Symfony

  • SERVICE CONTAINER

Symfony and Laravel apply similar approach in terms of services.

Service in PHP language means any object that is designed and in charge for a specific purpose, which is a complete performance of some universal task.

For example,
Sending e-mails out of the app.

Symfony differs through its rigid control over the structure and does not allow deviating from the accepted code pattern. Often this appears to be an additional challenge for the developer, but it allows the app to stay flexible and extensible to the maximum extent.

Laravel does not limit the developer through any rigid boundaries. It often provides for the possibility to cut corners and arrange things bypassing the pattern. In this case this is the developer, who is to make a decision, whether he/she will maintain and keep the structure or not.

  • LEARNING CURVE

The beginner developer is recommended to start with Laravel.

This framework was originally tooled for being easy-to-use and convenient for developers. Laravel creators tried to embody all the best features and characteristics in one. And judging by the fact that since 2015 Laravel has been called the most popular PHP framework, they did a stellar job.

Laravel has a short learning curve. This framework is full of magic. That is, its functions, for the most part, are just running, but there is no need to go into details as to how and why they run exactly this way. Just trust the framework and its high standards. The framework’s structure and main processes are all simple and easy-to-understand.

Symfony is much harder to be mastered, and this requires more time. Along with the framework itself, the developer needs to learn specific features of the programming language and technologies used to put into effect its possibilities.

iKeyless  - built using Laravel

No doubt, this Symfony vs Laravel 2017 list can be continued. We just wanted to draw some examples showing their different approach to development.

Meanwhile, in terms of support and updates, both frameworks have equal pros:

  • both enjoy the support of the advanced community;
  • detailed documentation is available for both frameworks;
  • lately, both frameworks have on a regular basis offered new tools.

Surely, in the foreseeable future they will continue making developers happy and their life easier.

And now let's imagine the situation when you may need to choose between Symfony and Laravel:

Do you need an app, and want to know how your future product will be developed?

Suppose, for any reason whatever, you have chosen PHP as a programming language for the future product. In such a case Umbrella IT team, as a rule, relies on one key criterion, in order to make the right choice:

PROJECT SPECIFIC FEATURES

Symfony is recommended for the following:

  • large and complex enterprise-level apps;
  • apps that play a pivotal role for the business;
  • ERP apps (enterprise resource planning).

In this case, these are reliability and stability that do matter. And Symfony framework review shows that Symfony is far from being unpredictable. Besides, Symfony has a ready release plan for the next six years. Therefore we should not await any “surprises” on the part of the framework.

Laravel is recommended for the following:

  • backend mobile apps;
  • standard apps;
  • small apps/startups that require being developed fast,
  • usage by beginner-developers.

In any case prior to making your choice of the toolset, analyze together with your developers the complete info about the future product (target audience, functions, expandability, etc).

This mean, start with defining WHAT you do. And then decide HOW to do it.

Any questions on these PHP framework, their specific features, and use? Contact us right now!

Photo: Shutterstock.com