Hoang ND

web developer

Symfony vs Laravel and the others

I could say I'm a Symfony fan boy. I'm using it for anything, for work, for personal projects. I even use Symfony to overcomplicate my own personal website. So yeah,  this is a biased post.

The other frameworks

Go back to the time everyone went crazy about Ruby on Rails (They still love it now), I started to learn PHP. A friend of mine recommended CakePHP, so i went ahead and learn it. I remembered they called it Ruby on Rails of PHP, and it was too opinionated for me, also too much syntactic sugar. Why don't I like syntactic sugar? It's not that sweet, it's a nightmare if something goes wrong - I don't know what's going on under every line of code. After few months tasted CakePHP, I went for something more complicated, more corporate like framework - Zend. That experience with Zend was really hurt. I couldn't get it to work, I didn't understand the configuration. I still hate the way they autoload class with Zend_SomeThing_SomeOtherThing_AndOtherThing for class name. What did I expect, it was dark age before namespace and composer sweetness. With hurtful feeling about Zend, I moved on with CodeIgniter. It was beautiful framework, lightweight, small footprint, easy to learn. It had everything I need, but then I realized its support for PHP4 and other stuffs from the Stone Age that pushed me away from the amazing framework. I intented to try Symfony 1, but after few days reading comments talk about how heavy, slow and unattractive it is, I thought I should stay away from it, at least until version 2. Then I decided to leave the "stupid" language that uses "->" instead of elegant "." for awhile.  I spent some time with Google App Engine, Ruby and beloved Flex. And then PHP suddenly became attractive with me again with the release of PHP 5.3, doctrine 2 and of course Symfony2.

Laravel

And now when everyone are crazy about the new frameworking stealing spotlight from other mature frameworks, I decided to check it out. To be honest all i have done with Laravel til now is just reading docs. These are just my opinions, initial impressions:

1. Laravel based on some Symfony2's bundles. I like this framework already, just like Drupal 8 and phpbb 4.

2. It seems to be an opinionated framework, I might have to use whatever the creator given in the framework. It a bit frustrating but not a big problem.

3. The syntax seems nice, at least it looks nice in my IDE :D

4. They even have their preconfigured development evironment. Oh men, I wish other frameworks had this when I started with PHP :(

5. Now the route. Route can only be defined in route.php file and using the same way? What if i have too many routes so the file become unreadable? There is only way/syntax to define route... so boring. I must say it sucks, lets hope there another way and another place i can define my route I don't know about...

Lets count how many ways I can define my route in Symfony2:

- I can define it in config file. It's a elegant and neat way to define route and  also easy to read. The file will not get cramped when I have a lot of routes because I can import routes from other config files.

# app/config/routing.yml
blog_show:
    path:      /blog/{slug}
    defaults:  { _controller: AcmeBlogBundle:Blog:show }

- I can define route using annotations. There is no reason I have to define route in a seperate file when I can define it in my controller file. No more switching file to edit routes, no more unwanted errors.

/**
 * @Route("/{id}", requirements={"id" = "\d+"}, defaults={"id" = 1})
 */
public function showAction($id)
{
}

- If that isn't enough for you, Symfony can store route definitions in database as well. Wait, there is more, you can using predefined route like above examples and database stored routes at the same time. You can even create your own rule for matching routes with controllers. 

6. View/Template: I think Blade kinda cool but not Twig cool. I think Twig is more elegant. If you use {{ }} to print variable why dont you use it for section and extends {{ extend('some_template') }} or {% extend('some_template') %} instead of @extends('some_template') would be less messy. And again, why don't you make it easier to me to use another template engine. I might be possible to use other template engine with  Laravel, but smarty is my second choice after twig. You shouldn't invent new template engine when there are very good engines exist.

7. Eloquent: I'm not really a fan of ActiveRecord, I prefer Data Mapper. It seems like everyone want to create their own ActiveRecord implementation (Zend, CakePHP, CodeIgnitor, Yii). Doctrine one of the reasons I like PHP, luckily, there are solutions to use Doctrine with Laravel.

Conclusion

Laravel seems like a beautiful framework. However, the framework is heavily influenced by the creator. Too opinionated framework might be easier to learn, but it is taking away flexibility (the best thing about Symfony2). 1 solution could not fit every case. I don't think Laravel is ready to build something big and complex, at least for now. Laravel is like a new CodeIgniter. It get things done faster but not better.

I could love Laravel the way I loved CodeIgniter, but it may take sometime for me to dig deeper to find the beauty in it.