Cover of the book Symfony 5: The Fast Track

Symfony 5: The Fast Track is the best book to learn modern Symfony development, from zero to production. +300 pages in full color showing how to combine Symfony with Docker, APIs, queues & async tasks, Webpack, Single-Page Applications, etc.

Buy printed version

New in Symfony 2.2: Logging of deprecated calls

The first Long Term Support version of Symfony2 will be 2.3, to be released in May 2013. In the meantime, we are in a race where we try to finish and polish everything as we won't allow BC breaks after 2.3 without a very good reason (a security issue for instance). So, since 2.0, instead of just replacing or removing existing features, we deprecate them and they will be removed in 2.3.

But how can you track those deprecated features? Of course, the CHANGELOGs and the UPGRADE file mention all the BC breaks and the deprecated features. But the code itself also contains some hints about deprecated methods and classes as they are tagged with @deprecated. But what if you miss some occurrences in your code? Will your code explode when upgrading to 2.3? The short answer is yes.

Contributed by
Colin Frei
in #6173 and #6180.

So, to provide a smoother transition, Symfony 2.2 introduces a new feature: the logging of deprecated calls. Whenever you call a deprecated method or whenever you create an instance of a deprecated class, Symfony will now log the call and alert you in the debug toolbar:

Deprecated calls logged in the web debug toolbar

Contributed by
Victor Berchet
in #6232.

That's really nice, but there is more. You can also go to the web profiler, and the log panel will tell you exactly where the call occurred:

Deprecated calls logged in the profiler

And if you have some functional tests, or just by browsing your application manually, you can automate everything by parsing the Symfony log file:

1
2
3
4
5
6
[2012-12-17 11:24:03] deprecation.WARNING: foo {
    "type":-100,
    "file":"/path/to/Controller/SomeController.php",
    "line":37,
    "stack":[/* stack trace not show here */]
}
Help the Symfony project!

As with any Open-Source project, contributing code or documentation is the most common way to help, but we also have a wide range of sponsoring opportunities.

Comments

Awesome!
One more awesome feature. Thanks.
great idea :-)
great feature! thanx.
I think I'm gonna love this tool :)
Love it :)
+1
Thanks Colin.

For those who ask "why -100 ?" (btw should be why '-100' ?). Twig bugs. I think Tobion has submitted a PR, I'll revisit the code.
This might be one of the best things ever!
Awesome!! +1
Nice feature !
Very nice, but usage of @deprecated annotation was not possible?
AWESOME!

Comments are closed.

To ensure that comments stay relevant, they are closed for old posts.