Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Use trigger_deprecation instead of @trigger_error #13379

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions 16 components/phpunit_bridge.rst
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,9 @@ Trigger Deprecation Notices

Deprecation notices can be triggered by using::

@trigger_error('Your deprecation message', E_USER_DEPRECATED);
trigger_deprecation('vendor-name/package-name', '5.1', 'Your deprecation message');

Without the `@-silencing operator`_, users would need to opt-out from deprecation
notices. Silencing by default swaps this behavior and allows users to opt-in
when they are ready to cope with them (by adding a custom error handler like the
one provided by this bridge). When not silenced, deprecation notices will appear
in the **Unsilenced** section of the deprecation report.
Where 5.1 is the version from which the deprecation starts. Note that the deprecation message can use the :phpfunction:`printf` format. In this case, you can pass placeholders as extra arguments after the deprecation message.
wouterj marked this conversation as resolved.
Show resolved Hide resolved

Mark Tests as Legacy
--------------------
Expand Down Expand Up @@ -354,14 +350,14 @@ times (order matters)::
public function testDeprecatedCode()
{
// test some code that triggers the following deprecation:
// @trigger_error('This "Foo" method is deprecated.', E_USER_DEPRECATED);
$this->expectDeprecation('This "%s" method is deprecated');
// trigger_deprecation('vendor-name/package-name', '5.1', 'This "Foo" method is deprecated.');
$this->expectDeprecation('Since vendor-name/package-name 5.1: This "%s" method is deprecated');

// ...

// test some code that triggers the following deprecation:
// @trigger_error('The second argument of the "Bar" method is deprecated.', E_USER_DEPRECATED);
$this->expectDeprecation('The second argument of the "%s" method is deprecated.');
// trigger_deprecation('vendor-name/package-name', '4.4', 'The second argument of the "Bar" method is deprecated.');
$this->expectDeprecation('Since vendor-name/package-name 4.4: The second argument of the "%s" method is deprecated.');
}
}

Expand Down
20 changes: 8 additions & 12 deletions 20 contributing/code/conventions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -100,40 +100,38 @@ A feature is marked as deprecated by adding a ``@deprecated`` PHPDoc to
relevant classes, methods, properties, ...::

/**
* @deprecated since Symfony 2.8.
* @deprecated since Symfony 5.1.
*/

The deprecation message must indicate the version in which the feature was deprecated,
and whenever possible, how it was replaced::

/**
* @deprecated since Symfony 2.8, use Replacement instead.
* @deprecated since Symfony 5.1, use Replacement instead.
*/

When the replacement is in another namespace than the deprecated class, its FQCN must be used::

/**
* @deprecated since Symfony 2.8, use A\B\Replacement instead.
* @deprecated since Symfony 5.1, use A\B\Replacement instead.
*/

A PHP ``E_USER_DEPRECATED`` error must also be triggered to help people with the migration::

@trigger_error(sprintf('The "%s" class is deprecated since Symfony 2.8, use "%s" instead.', Deprecated::class, Replacement::class), E_USER_DEPRECATED);
trigger_deprecation('vendor-name/package-name', '5.1', 'The "%s" class is deprecated since Symfony 5.1, use "%s" instead.', Deprecated::class, Replacement::class);
wouterj marked this conversation as resolved.
Show resolved Hide resolved

Without the `@-silencing operator`_, users would need to opt-out from deprecation
notices. Silencing swaps this behavior and allows users to opt-in when they are
ready to cope with them (by adding a custom error handler like the one used by
the Web Debug Toolbar or by the PHPUnit bridge).
The ``trigger_deprecation`` function internally use the php function :phpfunction:`assert`. This means you should use `zend.assertions` to disable deprecations in production.
wouterj marked this conversation as resolved.
Show resolved Hide resolved

When deprecating a whole class the ``trigger_error()`` call should be placed

When deprecating a whole class the ``trigger_deprecation()`` call should be placed
between the namespace and the use declarations, like in this example from
`ServiceRouterLoader`_::

namespace Symfony\Component\Routing\Loader\DependencyInjection;

use Symfony\Component\Routing\Loader\ContainerLoader;

@trigger_error(sprintf('The "%s" class is deprecated since Symfony 4.4, use "%s" instead.', ServiceRouterLoader::class, ContainerLoader::class), E_USER_DEPRECATED);
trigger_deprecation('symfony/routing', '4.4', 'The "%s" class is deprecated since Symfony 4.4, use "%s" instead.', ServiceRouterLoader::class, ContainerLoader::class);
wouterj marked this conversation as resolved.
Show resolved Hide resolved

/**
* @deprecated since Symfony 4.4, use Symfony\Component\Routing\Loader\ContainerLoader instead.
Expand Down Expand Up @@ -182,5 +180,3 @@ of the impacted component::
* Removed the `Deprecated` class, use `Replacement` instead.

This task is mandatory and must be done in the same pull request.

.. _`@-silencing operator`: https://www.php.net/manual/en/language.operators.errorcontrol.php
6 changes: 1 addition & 5 deletions 6 contributing/code/standards.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ short example containing most features described below::
*/
public function someDeprecatedMethod()
{
@trigger_error(sprintf('The %s() method is deprecated since vendor-name/package-name 2.8 and will be removed in 3.0. Use Acme\Baz::someMethod() instead.', __METHOD__), E_USER_DEPRECATED);
trigger_deprecation('vendor-name/package-name', '5.1', 'The %s() method is deprecated. Use Acme\Baz::someMethod() instead.', __METHOD__);

return Baz::someMethod();
}
Expand Down Expand Up @@ -187,10 +187,6 @@ Structure

* Exception and error message strings must be concatenated using :phpfunction:`sprintf`;

* Calls to :phpfunction:`trigger_error` with type ``E_USER_DEPRECATED`` must be
switched to opt-in via ``@`` operator.
Read more at :ref:`contributing-code-conventions-deprecations`;

* Do not use ``else``, ``elseif``, ``break`` after ``if`` and ``case`` conditions
which return or throw something;

Expand Down
2 changes: 1 addition & 1 deletion 2 contributing/community/reviews.rst
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ Pick a pull request from the `PRs in need of review`_ and follow these steps:
* Does the code break backward compatibility? If yes, does the PR header say
so?
* Does the PR contain deprecations? If yes, does the PR header say so? Does
the code contain ``trigger_error()`` statements for all deprecated
the code contain ``trigger_deprecation()`` statements for all deprecated
features?
* Are all deprecations and backward compatibility breaks documented in the
latest UPGRADE-X.X.md file? Do those explanations contain "Before"/"After"
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.