A few thoughts about the Symfony framework and PHP in general

by Ivo Lukač -

Although it is interesting to read bickering about PHP in the blog comments, forum threads, or Facebook group discussions, this post is not about comparing PHP with other languages. It is about an important factor that keeps PHP on the top - the frameworks. 

It is quite interesting to see blog comments, forum threads, or Facebook group discussions where PHP is being blasted as the worst programming language on a daily basis. Since plenty of people passionately defend it, the discussions end up in a flame war with no value whatsoever.

PHP: All things considered

This post is not about comparing PHP with other languages. I must say it would be hard to defend PHP anyway because it is true that it is probably the worst commonly used language after VBscript. But, the language itself is not the only thing being considered. When you are choosing which language to use in a certain situation, you consider other important factors as well:

  • the existing code base
  • global adoption
  • documentation
  • community activity
  • workforce potential
  • performance
  • flexibility
  • maintainability
  • best practices
  • use case fit
  • etc.

When considering what to learn and use, you should take into account the total outcome of these factors, not just each factor on its own.

A few months ago PHP turned 20. It started as a suite of scripts named Personal Home Page Tools. It was simple, it solved a problem, it made it easier to do the task. However, it has evolved enormously in the past 20 years, maturing into the most used web backend language and firmly holding that title thanks to the constant improvement of all the above-mentioned factors.

Yes, there still are some poor things in the syntax, but if it were such a big problem, PHP would never become so popular. Since it gained the momentum, it is difficult to persuade people to lose the "bad habit", but keep in mind that a lot of other companies/products were in an even better position and lost it in just a few years (remember Nokia). The PHP community is obviously doing something right year by year.

The importance of PHP frameworks (focusing on Symfony)

This post is about an important factor that, in my opinion, keeps PHP on the top - the frameworks. They represent another PHP strength as there are many frameworks and it is a great thing for the community to have options. However, we will talk mostly about Symfony since it's our framework of choice. I have already written on the reasons why we think Symfony is the best PHP framework. This doesn't mean Symfony is the main savior of the PHP, it is still just one of the several commonly used frameworks that the PHP developers use to build bigger and more complex projects and products.  

Like most of the other frameworks, Symfony brings a lot of features, but more importantly it brings conventions. For a one man band and a small project this might not be important, but in any other case it is. In real life, you want to solve problems efficiently. You don't want to lose time defining/implementing/testing something that has already been done by people much smarter than yourself. Many devs, especially the less experienced ones, are tempted to code everything from scratch because they want to do the best code possible. Intermediate ones might check other code but if they find something they don't like, they return to coding it themselves. This usually turns out to be a bad choice in the long run - in the long run, you want to have less code to maintain, upgrade, change. etc.

With a lot of influence from the other languages and proved paradigms, Symfony provides just that. It even has vendor support and LTS releases. Many big projects are starting to use Symfony and are even refactoring their legacy code. Besides eZ Publish, there are plenty of other projects going in that direction. In the last year, I have learned that the two web agencies from our city, Zagreb, Croatia are switching to Symfony.

In general, I think Symfony is the right choice because:

  • it’s well organized and has a flexible architecture
  • there’s no reinventing the wheel, it’s using existing proven components (Doctrine, PHPUnit, ...)
  • it’s decoupled a lot
  • has excellent documentation
  • has easy usable OOP features
  • has a big community

There was one more important thing that happened in 2009 and which was triggered by a few frameworks including Symfony - the PHP-FIG was summoned. The idea was to set some common ground like coding standards, logging, etc. for different frameworks so they can be more compatible. The most important outcome was the autoload specification (introduced in PSR-0, later improved in PSR-4), which wouldn’t be so important on its own, but which after two years led to another great improvement for the whole PHP community - Composer, the new dependency manager which is now de facto standard that enables the community to easily reuse code and to be more efficient. It is, in my opinion, one of the significant pillars of PHP today and in the adjacent future, and it came from framework devs’ engagement. The newest PSR is the PSR-7.

Our experience

By taking on framework conventions and using the dependency manager, we managed to do a quite complex solution with not so many hours spent. We used eZ Publish new stack CMS which is based on Symfony and installed Sylius eCommerce on top of it. The two very complex solutions now live in a single framework instance, in the same database, using the same ORM, the same routing, and the same templating engine. The services of one are easily called from the other. In my opinion, this is a big success for Symfony as a framework.

Frameworks enabled bigger projects and that pushed things to scale better. Also, the performance improvements are massive and noticeable. That was also influenced by what Facebook did to make PHP faster. This is an extreme use case which is well known and also very very special. A normal PHP project will never get to this point so the stock PHP should be enough. With the new PHP 7, the performance is very close to the HHVM open sourced by Facebook.

To us, the PHP future looks promising. PHP is here to stay, supported by Symfony and the other frameworks.

Comments

This site uses cookies. Some of these cookies are essential, while others help us improve your experience by providing insights into how the site is being used.

For more detailed information on the cookies we use, please check our Privacy Policy.

  • Necessary cookies enable core functionality. The website cannot function properly without these cookies, and can only be disabled by changing your browser preferences.