Skip to content

Commit 2368af7

Browse files
Merge branch '5.4' into 6.0
* 5.4: [Messenger] cs fix [Messenger] Fix time-limit check exception [Console] Fix console `ProgressBar::override()` after manual `ProgressBar::cleanup()` [FrameworkBundle] typo default_lifetime example [HttpClient] Handle Amp HTTP client v5 incompatibility gracefully [HttpKernel] Don’t try to wire Response argument with controller.service_arguments [PhpUnitBridge] Fix language deprecations incorrectly marked as direct Tell about messenger:consume invalid limit options [Messenger] Do not throw 'no handlers' exception when skipping due to duplicate handling
2 parents 9a87abd + 5ea977e commit 2368af7

File tree

4 files changed

+69
-3
lines changed

4 files changed

+69
-3
lines changed

DeprecationErrorHandler.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public function handleError($type, $msg, $file, $line, $context = [])
132132
$msg = $trace[1]['args'][0];
133133
}
134134

135-
$deprecation = new Deprecation($msg, $trace, $file);
135+
$deprecation = new Deprecation($msg, $trace, $file, \E_DEPRECATED === $type);
136136
if ($deprecation->isMuted()) {
137137
return null;
138138
}

DeprecationErrorHandler/Deprecation.php

+10-2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class Deprecation
3737

3838
private $trace = [];
3939
private $message;
40+
private $languageDeprecation;
4041
private $originClass;
4142
private $originMethod;
4243
private $triggeringFile;
@@ -56,8 +57,9 @@ class Deprecation
5657
/**
5758
* @param string $message
5859
* @param string $file
60+
* @param bool $languageDeprecation
5961
*/
60-
public function __construct($message, array $trace, $file)
62+
public function __construct($message, array $trace, $file, $languageDeprecation = false)
6163
{
6264
if (isset($trace[2]['function']) && 'trigger_deprecation' === $trace[2]['function']) {
6365
$file = $trace[2]['file'];
@@ -66,6 +68,7 @@ public function __construct($message, array $trace, $file)
6668

6769
$this->trace = $trace;
6870
$this->message = $message;
71+
$this->languageDeprecation = $languageDeprecation;
6972

7073
$i = \count($trace);
7174
while (1 < $i && $this->lineShouldBeSkipped($trace[--$i])) {
@@ -239,7 +242,12 @@ public function isMuted()
239242
*/
240243
public function getType()
241244
{
242-
if (self::PATH_TYPE_SELF === $pathType = $this->getPathType($this->triggeringFile)) {
245+
$pathType = $this->getPathType($this->triggeringFile);
246+
if ($this->languageDeprecation && self::PATH_TYPE_VENDOR === $pathType) {
247+
// the triggering file must be used for language deprecations
248+
return self::TYPE_INDIRECT;
249+
}
250+
if (self::PATH_TYPE_SELF === $pathType) {
243251
return self::TYPE_SELF;
244252
}
245253
if (self::PATH_TYPE_UNDETERMINED === $pathType) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace acme\lib;
4+
5+
class PhpDeprecation implements \Serializable
6+
{
7+
public function serialize(): string
8+
{
9+
return serialize([]);
10+
}
11+
12+
public function unserialize($data): void
13+
{
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
--TEST--
2+
Test that a PHP deprecation from a vendor class autoload is considered indirect.
3+
--SKIPIF--
4+
<?php if (\PHP_VERSION_ID < 80100) echo 'skip'; ?>
5+
--FILE--
6+
<?php
7+
8+
$k = 'SYMFONY_DEPRECATIONS_HELPER';
9+
putenv($k.'='.$_SERVER[$k] = $_ENV[$k] = 'max[total]=0');
10+
putenv('ANSICON');
11+
putenv('ConEmuANSI');
12+
putenv('TERM');
13+
14+
$vendor = __DIR__;
15+
while (!file_exists($vendor.'/vendor')) {
16+
$vendor = dirname($vendor);
17+
}
18+
define('PHPUNIT_COMPOSER_INSTALL', $vendor.'/vendor/autoload.php');
19+
require PHPUNIT_COMPOSER_INSTALL;
20+
require_once __DIR__.'/../../bootstrap.php';
21+
eval(<<<'EOPHP'
22+
namespace PHPUnit\Util;
23+
24+
class Test
25+
{
26+
public static function getGroups()
27+
{
28+
return array();
29+
}
30+
}
31+
EOPHP
32+
);
33+
require __DIR__.'/fake_vendor/autoload.php';
34+
35+
\Symfony\Component\ErrorHandler\DebugClassLoader::enable();
36+
new \acme\lib\PhpDeprecation();
37+
38+
?>
39+
--EXPECTF--
40+
Remaining indirect deprecation notices (1)
41+
42+
1x: acme\lib\PhpDeprecation implements the Serializable interface, which is deprecated. Implement __serialize() and __unserialize() instead (or in addition, if support for old PHP versions is necessary)
43+
1x in DebugClassLoader::loadClass from Symfony\Component\ErrorHandler

0 commit comments

Comments
 (0)