Skip to content

Commit 099fc6c

Browse files
Merge branch '6.1' into 6.2
* 6.1: [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 [FrameworkBundle] Removed unused $willBeAvailable params on Configuration [Cache] Remove extra type condition in MemcachedAdapter::createConnection() Tell about messenger:consume invalid limit options [Messenger] Do not throw 'no handlers' exception when skipping due to duplicate handling
2 parents 458475e + c8163ef commit 099fc6c

File tree

4 files changed

+69
-3
lines changed

4 files changed

+69
-3
lines changed

DeprecationErrorHandler.php

Lines changed: 1 addition & 1 deletion
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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class Deprecation
3636

3737
private $trace = [];
3838
private $message;
39+
private $languageDeprecation;
3940
private $originClass;
4041
private $originMethod;
4142
private $triggeringFile;
@@ -55,8 +56,9 @@ class Deprecation
5556
/**
5657
* @param string $message
5758
* @param string $file
59+
* @param bool $languageDeprecation
5860
*/
59-
public function __construct($message, array $trace, $file)
61+
public function __construct($message, array $trace, $file, $languageDeprecation = false)
6062
{
6163
if (isset($trace[2]['function']) && 'trigger_deprecation' === $trace[2]['function']) {
6264
$file = $trace[2]['file'];
@@ -65,6 +67,7 @@ public function __construct($message, array $trace, $file)
6567

6668
$this->trace = $trace;
6769
$this->message = $message;
70+
$this->languageDeprecation = $languageDeprecation;
6871

6972
$i = \count($trace);
7073
while (1 < $i && $this->lineShouldBeSkipped($trace[--$i])) {
@@ -238,7 +241,12 @@ public function isMuted()
238241
*/
239242
public function getType()
240243
{
241-
if (self::PATH_TYPE_SELF === $pathType = $this->getPathType($this->triggeringFile)) {
244+
$pathType = $this->getPathType($this->triggeringFile);
245+
if ($this->languageDeprecation && self::PATH_TYPE_VENDOR === $pathType) {
246+
// the triggering file must be used for language deprecations
247+
return self::TYPE_INDIRECT;
248+
}
249+
if (self::PATH_TYPE_SELF === $pathType) {
242250
return self::TYPE_SELF;
243251
}
244252
if (self::PATH_TYPE_UNDETERMINED === $pathType) {
Lines changed: 15 additions & 0 deletions
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+
}
Lines changed: 43 additions & 0 deletions
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)