Choosing a good PHP framework provides the right building blocks to make developing your app a breeze. Today we’re going to look at two PHP frameworks: Laravel and Symfony.
We’ll compare them, score them, and declare a winner. Along the way, you’ll choose the framework that’s right for you and your product.
Both Symfony and Laravel provide cross-platform PHP frameworks and features that speed up the development of your PHP application. The scaffolding of the application helps define its structure, and the plugins extend your ability to add features quickly.
From a baseline perspective, both options start in a good place. What differentiates the two, however, depends on the specific application and developer needs.
It’s easiest to define differences by categorizing similar features and benefits. Once categorized, a series of questions start to emerge. Answer these questions, and the best option for your specific application should distinguish itself.
Though you shouldn’t choose a PHP framework on popularity alone, there are some benefits a large user-base brings to a framework.
Laravel is the most popular PHP framework, but Symfony still ends up high on the list at number two.
With popularity comes a large amount of training and support information online. For Laravel, tutorials through Laracasts can provide excellent information that Symfony currently doesn’t provide. Though Symfony still shares great documentation, the resources are not as extensive as those for Laravel.
In older versions, Laravel performed better than Symfony.
However, with improvements in Symfony 4+, Laravel’s edge shrunk down close to nothing. The performance gains that Laravel once boasted might not be there anymore.
As long as you’re using the latest and greatest version of each PHP framework, performance is a toss-up. Therefore, there’s no change in score.
Symfony contains reusable components, which provide more modularity. It organizes the code in a cleaner way, making it a great fit for larger and more complex projects. This is why many experienced PHP developers prefer Symfony over Laravel.
Additionally, Laravel’s strength revolves around MVC-based apps. Once you start to wander away from the MVC paradigm, Laravel can’t help you.
Using Laravel to get up and running will leave your Symfony cohorts in the dust thanks to a useful set of pre-built dependencies that you’ll need. However, if you’re building a large scale application, picking and choosing your dependencies and plugins makes the application easier to enhance and scale. For this section, the point goes to Symfony for flexibility and modularity.
Pro Tip: As you begin to scale and projects become larger and more complex, consider using an APM tool like Retrace to help monitor code and identify errors in the pre-production pipeline.
PHP in itself is a templating engine.
However, providing additional templating engines provides more advanced templating with less syntax. Using other templating engines helps keep the business logic in the PHP and presentation logic within the templating engine.
While Symfony provides Twig as the default templating engine, Laravel provides a bit more.
Laravel’s default templating engine Blade has lots for everyone, Blade provides advantages over Twig, as it allows for code reusability that doesn’t exist in Twig. Additionally, Laravel brings in Lumen, a sub-framework for building APIs and microservices. Bonus!
Both Laravel and Symfony provide object-relational mapping (ORM) for data access. With Symfony, Doctrine handles ORM, while Eloquent provides ORM for Laravel. With ORM, data manipulation becomes much simpler in either PHP framework.
There are a number of database-related differences between the two PHP frameworks.
First, let’s look at what databases each PHP framework supports.
|SAP Sybase SQL Anywhere||–||X|
As you can see with the table, Symfony provides a few additional options. So, if you’re going for breadth, Symfony wins this one.
With Symfony, database migrations are automatic. They just need simple definitions for the fields in the model. So that seems like a quick win, but let’s look further. When considering Laravel, database migrations are manual, but they don’t require defining the fields!
With Laravel, accessing the data requires more knowledge of SQL. That’s not the case with Symfony, although it requires that you create a repository function for each call. If your application uses a complicated database structure, that may result in a large number of repository functions.
On the other hand, Eloquent tends to tie your application to your DB schema design. Changing a column name could result in changes throughout your codebase. Doctrine, and Symfony, by extension, use a mapper pattern, so you can delineate between your database schema and your business objects and logic.
Taking all of that data into account, I’m going to go with Symfony for this
FYI: If your app relies on a database, you know that problems in the database often have wide-reaching impact downstream. Retrace’s SQL Monitors are a great way to more proactively keep tabs on data and database health.
There’s not a particular technology that’s better across the board.
It all depends on what problems you have and which technology can best solve those problems.
Try both to see which works best for your use case. Experiment and play with the features that are most important to you.