Skip to content

Commit e7e48c8

Browse files
bug #14900 Silence deprecation warnings by default (reecefowell)
This PR was merged into the 2.7 branch. Discussion ---------- [RFC] Fixing Deprecation Warnings This PR address an issue that causes Symfony to vomit E_DEPRECATED warnings everywhere. ```markdown | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #14899 | License | MIT ``` Fixes #14899 ![http://cdn.meme.am/instances2/500x/125359.jpg](http://cdn.meme.am/instances2/500x/125359.jpg) Commits ------- 73bbaa6 Silence invasive deprecation warnings, opt-in for warnings
2 parents d23d3c9 + 73bbaa6 commit e7e48c8

File tree

204 files changed

+326
-337
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

204 files changed

+326
-337
lines changed

UPGRADE-2.7.md

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,16 @@ UPGRADE FROM 2.6 to 2.7
44
Global
55
------
66

7-
* `E_USER_DEPRECATED` warnings -
8-
`trigger_error('... is deprecated ...', E_USER_DEPRECATED)` -
9-
are now triggered when using all deprecated functionality.
10-
To avoid filling up error logs, you may need to add
11-
`~E_USER_DEPRECATED` to your `error_reporting` setting in
12-
`php.ini` to *not* add these errors to your log.
13-
14-
In the Symfony Framework, `~E_USER_DEPRECATED` is added to
15-
`bootstrap.php.cache` automatically, but you need at least
16-
version `2.3.14` or `3.0.21` of the
17-
[SensioDistributionBundle](https://github.com/sensiolabs/SensioDistributionBundle).
18-
So, you may need to upgrade:
19-
20-
```bash
21-
composer update sensio/distribution-bundle
22-
```
23-
24-
The [phpunit-bridge](https://github.com/symfony/phpunit-bridge)
25-
was introduced to silence deprecation warnings while running your
26-
tests and give you a report of deprecated function calls.
7+
* Deprecation notices -
8+
`@trigger_error('... is deprecated ...', E_USER_DEPRECATED)` -
9+
are now triggered when using any deprecated functionality.
10+
11+
By default these notices are silenced, so they won't appear in the PHP logs of
12+
your production server. However, these notices are still visible in the web
13+
debug toolbar, so you can know where your code needs an upgrade.
14+
15+
In addition, it's strongly recommended to enable the [phpunit-bridge](https://github.com/symfony/phpunit-bridge)
16+
so that you can deal with deprecation notices in your test suite.
2717

2818
Router
2919
------

src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace Symfony\Bridge\Doctrine\Form\ChoiceList;
1313

14-
trigger_error('The '.__NAMESPACE__.'\EntityChoiceList class is deprecated since version 2.7 and will be removed in 3.0. Use Symfony\Bridge\Doctrine\Form\ChoiceList\DoctrineChoiceLoader instead.', E_USER_DEPRECATED);
14+
@trigger_error('The '.__NAMESPACE__.'\EntityChoiceList class is deprecated since version 2.7 and will be removed in 3.0. Use Symfony\Bridge\Doctrine\Form\ChoiceList\DoctrineChoiceLoader instead.', E_USER_DEPRECATED);
1515

1616
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
1717
use Doctrine\Common\Persistence\ObjectManager;
@@ -300,12 +300,11 @@ public function getValuesForChoices(array $entities)
300300
* @return array
301301
*
302302
* @see ChoiceListInterface
303-
*
304303
* @deprecated since version 2.4, to be removed in 3.0.
305304
*/
306305
public function getIndicesForChoices(array $entities)
307306
{
308-
trigger_error('The '.__METHOD__.' method is deprecated since version 2.4 and will be removed in 3.0.', E_USER_DEPRECATED);
307+
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.4 and will be removed in 3.0.', E_USER_DEPRECATED);
309308

310309
// Performance optimization
311310
if (empty($entities)) {
@@ -344,12 +343,11 @@ public function getIndicesForChoices(array $entities)
344343
* @return array
345344
*
346345
* @see ChoiceListInterface
347-
*
348346
* @deprecated since version 2.4, to be removed in 3.0.
349347
*/
350348
public function getIndicesForValues(array $values)
351349
{
352-
trigger_error('The '.__METHOD__.' method is deprecated since version 2.4 and will be removed in 3.0.', E_USER_DEPRECATED);
350+
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.4 and will be removed in 3.0.', E_USER_DEPRECATED);
353351

354352
// Performance optimization
355353
if (empty($values)) {

src/Symfony/Bridge/Doctrine/Form/ChoiceList/ORMQueryBuilderLoader.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@ public function __construct($queryBuilder, $manager = null, $class = null)
5757
}
5858

5959
if ($queryBuilder instanceof \Closure) {
60-
trigger_error('Passing a QueryBuilder closure to '.__CLASS__.'::__construct() is deprecated since version 2.7 and will be removed in 3.0.', E_USER_DEPRECATED);
60+
@trigger_error('Passing a QueryBuilder closure to '.__CLASS__.'::__construct() is deprecated since version 2.7 and will be removed in 3.0.', E_USER_DEPRECATED);
6161

6262
if (!$manager instanceof EntityManager) {
6363
throw new UnexpectedTypeException($manager, 'Doctrine\ORM\EntityManager');
6464
}
6565

66-
trigger_error('Passing an EntityManager to '.__CLASS__.'::__construct() is deprecated since version 2.7 and will be removed in 3.0.', E_USER_DEPRECATED);
67-
trigger_error('Passing a class to '.__CLASS__.'::__construct() is deprecated since version 2.7 and will be removed in 3.0.', E_USER_DEPRECATED);
66+
@trigger_error('Passing an EntityManager to '.__CLASS__.'::__construct() is deprecated since version 2.7 and will be removed in 3.0.', E_USER_DEPRECATED);
67+
@trigger_error('Passing a class to '.__CLASS__.'::__construct() is deprecated since version 2.7 and will be removed in 3.0.', E_USER_DEPRECATED);
6868

6969
$queryBuilder = $queryBuilder($manager->getRepository($class));
7070

src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ public function configureOptions(OptionsResolver $resolver)
248248
// deprecation note
249249
$propertyNormalizer = function (Options $options, $propertyName) {
250250
if ($propertyName) {
251-
trigger_error('The "property" option is deprecated since version 2.7 and will be removed in 3.0. Use "choice_label" instead.', E_USER_DEPRECATED);
251+
@trigger_error('The "property" option is deprecated since version 2.7 and will be removed in 3.0. Use "choice_label" instead.', E_USER_DEPRECATED);
252252
}
253253

254254
return $propertyName;
@@ -267,7 +267,7 @@ public function configureOptions(OptionsResolver $resolver)
267267
// deprecation note
268268
$loaderNormalizer = function (Options $options, $loader) {
269269
if ($loader) {
270-
trigger_error('The "loader" option is deprecated since version 2.7 and will be removed in 3.0. Override getLoader() instead.', E_USER_DEPRECATED);
270+
@trigger_error('The "loader" option is deprecated since version 2.7 and will be removed in 3.0. Override getLoader() instead.', E_USER_DEPRECATED);
271271
}
272272

273273
return $loader;

src/Symfony/Bridge/Doctrine/Tests/DoctrineOrmTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace Symfony\Bridge\Doctrine\Tests;
1313

14-
trigger_error('The '.__NAMESPACE__.'\DoctrineOrmTestCase class is deprecated since version 2.4 and will be removed in 3.0. Use Symfony\Bridge\Doctrine\Test\DoctrineTestHelper class instead.', E_USER_DEPRECATED);
14+
@trigger_error('The '.__NAMESPACE__.'\DoctrineOrmTestCase class is deprecated since version 2.4 and will be removed in 3.0. Use Symfony\Bridge\Doctrine\Test\DoctrineTestHelper class instead.', E_USER_DEPRECATED);
1515

1616
use Doctrine\ORM\EntityManager;
1717
use Symfony\Bridge\Doctrine\Test\DoctrineTestHelper;

src/Symfony/Bridge/Monolog/Logger.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Logger extends BaseLogger implements LoggerInterface, DebugLoggerInterface
2727
*/
2828
public function emerg($message, array $context = array())
2929
{
30-
trigger_error('The '.__METHOD__.' method inherited from the Symfony\Component\HttpKernel\Log\LoggerInterface interface is deprecated since version 2.2 and will be removed in 3.0. Use the emergency() method instead, which is PSR-3 compatible.', E_USER_DEPRECATED);
30+
@trigger_error('The '.__METHOD__.' method inherited from the Symfony\Component\HttpKernel\Log\LoggerInterface interface is deprecated since version 2.2 and will be removed in 3.0. Use the emergency() method instead, which is PSR-3 compatible.', E_USER_DEPRECATED);
3131

3232
return parent::addRecord(BaseLogger::EMERGENCY, $message, $context);
3333
}
@@ -37,7 +37,7 @@ public function emerg($message, array $context = array())
3737
*/
3838
public function crit($message, array $context = array())
3939
{
40-
trigger_error('The '.__METHOD__.' method inherited from the Symfony\Component\HttpKernel\Log\LoggerInterface interface is deprecated since version 2.2 and will be removed in 3.0. Use the method critical() method instead, which is PSR-3 compatible.', E_USER_DEPRECATED);
40+
@trigger_error('The '.__METHOD__.' method inherited from the Symfony\Component\HttpKernel\Log\LoggerInterface interface is deprecated since version 2.2 and will be removed in 3.0. Use the method critical() method instead, which is PSR-3 compatible.', E_USER_DEPRECATED);
4141

4242
return parent::addRecord(BaseLogger::CRITICAL, $message, $context);
4343
}
@@ -47,7 +47,7 @@ public function crit($message, array $context = array())
4747
*/
4848
public function err($message, array $context = array())
4949
{
50-
trigger_error('The '.__METHOD__.' method inherited from the Symfony\Component\HttpKernel\Log\LoggerInterface interface is deprecated since version 2.2 and will be removed in 3.0. Use the error() method instead, which is PSR-3 compatible.', E_USER_DEPRECATED);
50+
@trigger_error('The '.__METHOD__.' method inherited from the Symfony\Component\HttpKernel\Log\LoggerInterface interface is deprecated since version 2.2 and will be removed in 3.0. Use the error() method instead, which is PSR-3 compatible.', E_USER_DEPRECATED);
5151

5252
return parent::addRecord(BaseLogger::ERROR, $message, $context);
5353
}
@@ -57,7 +57,7 @@ public function err($message, array $context = array())
5757
*/
5858
public function warn($message, array $context = array())
5959
{
60-
trigger_error('The '.__METHOD__.' method inherited from the Symfony\Component\HttpKernel\Log\LoggerInterface interface is deprecated since version 2.2 and will be removed in 3.0. Use the warning() method instead, which is PSR-3 compatible.', E_USER_DEPRECATED);
60+
@trigger_error('The '.__METHOD__.' method inherited from the Symfony\Component\HttpKernel\Log\LoggerInterface interface is deprecated since version 2.2 and will be removed in 3.0. Use the warning() method instead, which is PSR-3 compatible.', E_USER_DEPRECATED);
6161

6262
return parent::addRecord(BaseLogger::WARNING, $message, $context);
6363
}

src/Symfony/Bridge/Swiftmailer/DataCollector/MessageDataCollector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace Symfony\Bridge\Swiftmailer\DataCollector;
1313

14-
trigger_error(__CLASS__.' class is deprecated since version 2.4 and will be removed in 3.0. Use the Symfony\Bundle\SwiftmailerBundle\DataCollector\MessageDataCollector class from SwiftmailerBundle instead. Require symfony/swiftmailer-bundle package to download SwiftmailerBundle with Composer.', E_USER_DEPRECATED);
14+
@trigger_error(__CLASS__.' class is deprecated since version 2.4 and will be removed in 3.0. Use the Symfony\Bundle\SwiftmailerBundle\DataCollector\MessageDataCollector class from SwiftmailerBundle instead. Require symfony/swiftmailer-bundle package to download SwiftmailerBundle with Composer.', E_USER_DEPRECATED);
1515

1616
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
1717
use Symfony\Component\HttpFoundation\Request;

src/Symfony/Bridge/Twig/AppVariable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function setDebug($debug)
6868
*/
6969
public function getSecurity()
7070
{
71-
trigger_error('The "app.security" variable is deprecated since version 2.6 and will be removed in 3.0.', E_USER_DEPRECATED);
71+
@trigger_error('The "app.security" variable is deprecated since version 2.6 and will be removed in 3.0.', E_USER_DEPRECATED);
7272

7373
if (null === $this->container) {
7474
throw new \RuntimeException('The "app.security" variable is not available.');

src/Symfony/Bridge/Twig/Extension/AssetExtension.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ public function getAssetUrl($path, $packageName = null, $absolute = false, $vers
6161
{
6262
// BC layer to be removed in 3.0
6363
if (2 < $count = func_num_args()) {
64-
trigger_error('Generating absolute URLs with the Twig asset() function was deprecated in 2.7 and will be removed in 3.0. Please use absolute_url() instead.', E_USER_DEPRECATED);
64+
@trigger_error('Generating absolute URLs with the Twig asset() function was deprecated in 2.7 and will be removed in 3.0. Please use absolute_url() instead.', E_USER_DEPRECATED);
6565
if (4 === $count) {
66-
trigger_error('Forcing a version with the Twig asset() function was deprecated in 2.7 and will be removed in 3.0.', E_USER_DEPRECATED);
66+
@trigger_error('Forcing a version with the Twig asset() function was deprecated in 2.7 and will be removed in 3.0.', E_USER_DEPRECATED);
6767
}
6868

6969
$args = func_get_args();
@@ -89,7 +89,7 @@ public function getAssetVersion($path, $packageName = null)
8989

9090
public function getAssetsVersion($packageName = null)
9191
{
92-
trigger_error('The Twig assets_version() function was deprecated in 2.7 and will be removed in 3.0. Please use asset_version() instead.', E_USER_DEPRECATED);
92+
@trigger_error('The Twig assets_version() function was deprecated in 2.7 and will be removed in 3.0. Please use asset_version() instead.', E_USER_DEPRECATED);
9393

9494
return $this->packages->getVersion('/', $packageName);
9595
}

src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ protected function addFlash($type, $message)
120120
* @param mixed $object The object
121121
*
122122
* @throws \LogicException
123+
*
123124
* @return bool
124125
*/
125126
protected function isGranted($attributes, $object = null)
@@ -273,7 +274,7 @@ public function createFormBuilder($data = null, array $options = array())
273274
*/
274275
public function getRequest()
275276
{
276-
trigger_error('The '.__METHOD__.' method is deprecated since version 2.4 and will be removed in 3.0. The only reliable way to get the "Request" object is to inject it in the action method.', E_USER_DEPRECATED);
277+
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.4 and will be removed in 3.0. The only reliable way to get the "Request" object is to inject it in the action method.', E_USER_DEPRECATED);
277278

278279
return $this->container->get('request_stack')->getCurrentRequest();
279280
}
@@ -343,7 +344,7 @@ public function has($id)
343344
public function get($id)
344345
{
345346
if ('request' === $id) {
346-
trigger_error('The "request" service is deprecated and will be removed in 3.0. Add a typehint for Symfony\\Component\\HttpFoundation\\Request to your controller parameters to retrieve the request instead.', E_USER_DEPRECATED);
347+
@trigger_error('The "request" service is deprecated and will be removed in 3.0. Add a typehint for Symfony\\Component\\HttpFoundation\\Request to your controller parameters to retrieve the request instead.', E_USER_DEPRECATED);
347348
}
348349

349350
return $this->container->get($id);
@@ -362,7 +363,7 @@ protected function getParameter($name)
362363
}
363364

364365
/**
365-
* Checks the validity of a CSRF token
366+
* Checks the validity of a CSRF token.
366367
*
367368
* @param string $id The id used when generating the token
368369
* @param string $token The actual token sent with the request that should be validated

0 commit comments

Comments
 (0)