New in Symfony 2.2: Logging of deprecated calls
December 17, 2012 • Published by Fabien Potencier
Warning: This post is about an unsupported Symfony version. Some of this information may be out of date. Read the most recent Symfony Docs.
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.
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:
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:
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 are closed.
To ensure that comments stay relevant, they are closed for old posts.
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.