You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feature symfony#13379 Use trigger_deprecation instead of @trigger_error (l-vo)
This PR was merged into the master branch.
Discussion
----------
Use trigger_deprecation instead of @trigger_error
Commits
-------
6702c1e Use trigger_deprecation instead of @trigger_error
Without the `@-silencing operator`_, users would need to opt-out from deprecation
169
-
notices. Silencing by default swaps this behavior and allows users to opt-in
170
-
when they are ready to cope with them (by adding a custom error handler like the
171
-
one provided by this bridge). When not silenced, deprecation notices will appear
172
-
in the **Unsilenced** section of the deprecation report.
168
+
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.
173
169
174
170
Mark Tests as Legacy
175
171
--------------------
@@ -354,14 +350,14 @@ times (order matters)::
354
350
public function testDeprecatedCode()
355
351
{
356
352
// test some code that triggers the following deprecation:
357
-
// @trigger_error('This "Foo" method is deprecated.', E_USER_DEPRECATED);
358
-
$this->expectDeprecation('This "%s" method is deprecated');
353
+
// trigger_deprecation('vendor-name/package-name', '5.1', 'This "Foo" method is deprecated.');
354
+
$this->expectDeprecation('Since vendor-name/package-name 5.1: This "%s" method is deprecated');
359
355
360
356
// ...
361
357
362
358
// test some code that triggers the following deprecation:
363
-
// @trigger_error('The second argument of the "Bar" method is deprecated.', E_USER_DEPRECATED);
364
-
$this->expectDeprecation('The second argument of the "%s" method is deprecated.');
359
+
// trigger_deprecation('vendor-name/package-name', '4.4', 'The second argument of the "Bar" method is deprecated.');
360
+
$this->expectDeprecation('Since vendor-name/package-name 4.4: The second argument of the "%s" method is deprecated.');
Copy file name to clipboardExpand all lines: contributing/code/conventions.rst
+8-12
Original file line number
Diff line number
Diff line change
@@ -100,40 +100,38 @@ A feature is marked as deprecated by adding a ``@deprecated`` PHPDoc to
100
100
relevant classes, methods, properties, ...::
101
101
102
102
/**
103
-
* @deprecated since Symfony 2.8.
103
+
* @deprecated since Symfony 5.1.
104
104
*/
105
105
106
106
The deprecation message must indicate the version in which the feature was deprecated,
107
107
and whenever possible, how it was replaced::
108
108
109
109
/**
110
-
* @deprecated since Symfony 2.8, use Replacement instead.
110
+
* @deprecated since Symfony 5.1, use Replacement instead.
111
111
*/
112
112
113
113
When the replacement is in another namespace than the deprecated class, its FQCN must be used::
114
114
115
115
/**
116
-
* @deprecated since Symfony 2.8, use A\B\Replacement instead.
116
+
* @deprecated since Symfony 5.1, use A\B\Replacement instead.
117
117
*/
118
118
119
119
A PHP ``E_USER_DEPRECATED`` error must also be triggered to help people with the migration::
120
120
121
-
@trigger_error(sprintf('The "%s" class is deprecated since Symfony 2.8, use "%s" instead.', Deprecated::class, Replacement::class), E_USER_DEPRECATED);
121
+
trigger_deprecation('vendor-name/package-name', '5.1', 'The "%s" class is deprecated since Symfony 5.1, use "%s" instead.', Deprecated::class, Replacement::class);
122
122
123
-
Without the `@-silencing operator`_, users would need to opt-out from deprecation
124
-
notices. Silencing swaps this behavior and allows users to opt-in when they are
125
-
ready to cope with them (by adding a custom error handler like the one used by
126
-
the Web Debug Toolbar or by the PHPUnit bridge).
123
+
The ``trigger_deprecation`` function internally use the php function :phpfunction:`assert`. This means you should use `zend.assertions` to disable deprecations in production.
127
124
128
-
When deprecating a whole class the ``trigger_error()`` call should be placed
125
+
126
+
When deprecating a whole class the ``trigger_deprecation()`` call should be placed
129
127
between the namespace and the use declarations, like in this example from
use Symfony\Component\Routing\Loader\ContainerLoader;
135
133
136
-
@trigger_error(sprintf('The "%s" class is deprecated since Symfony 4.4, use "%s" instead.', ServiceRouterLoader::class, ContainerLoader::class), E_USER_DEPRECATED);
134
+
trigger_deprecation('symfony/routing', '4.4', 'The "%s" class is deprecated since Symfony 4.4, use "%s" instead.', ServiceRouterLoader::class, ContainerLoader::class);
137
135
138
136
/**
139
137
* @deprecated since Symfony 4.4, use Symfony\Component\Routing\Loader\ContainerLoader instead.
@@ -182,5 +180,3 @@ of the impacted component::
182
180
* Removed the `Deprecated` class, use `Replacement` instead.
183
181
184
182
This task is mandatory and must be done in the same pull request.
Copy file name to clipboardExpand all lines: contributing/code/standards.rst
+1-5
Original file line number
Diff line number
Diff line change
@@ -72,7 +72,7 @@ short example containing most features described below::
72
72
*/
73
73
public function someDeprecatedMethod()
74
74
{
75
-
@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);
75
+
trigger_deprecation('vendor-name/package-name', '5.1', 'The %s() method is deprecated. Use Acme\Baz::someMethod() instead.', __METHOD__);
76
76
77
77
return Baz::someMethod();
78
78
}
@@ -187,10 +187,6 @@ Structure
187
187
188
188
* Exception and error message strings must be concatenated using :phpfunction:`sprintf`;
189
189
190
-
* Calls to :phpfunction:`trigger_error` with type ``E_USER_DEPRECATED`` must be
191
-
switched to opt-in via ``@`` operator.
192
-
Read more at :ref:`contributing-code-conventions-deprecations`;
193
-
194
190
* Do not use ``else``, ``elseif``, ``break`` after ``if`` and ``case`` conditions
0 commit comments