Skip to content

Commit 9eb522e

Browse files
bug symfony#17320 [Debug] Fixed erroneous deprecation notice for extended Interfaces (peterrehm)
This PR was merged into the 2.8 branch. Discussion ---------- [Debug] Fixed erroneous deprecation notice for extended Interfaces | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony#16643, symfony#16775 | License | MIT | Doc PR | - Replaces symfony#16775. Commits ------- 5f4e968 Fixed erroneous deprecation notice for extended Interfaces
2 parents 0df74c8 + 5f4e968 commit 9eb522e

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

src/Symfony/Component/Debug/DebugClassLoader.php

+18-1
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,25 @@ public function loadClass($class)
200200
@trigger_error(sprintf('The %s class extends %s that is deprecated %s', $name, $parent->name, self::$deprecated[$parent->name]), E_USER_DEPRECATED);
201201
}
202202

203+
$parentInterfaces = array();
204+
$deprecatedInterfaces = array();
205+
if ($parent) {
206+
foreach ($parent->getInterfaceNames() as $interface) {
207+
$parentInterfaces[$interface] = 1;
208+
}
209+
}
210+
203211
foreach ($refl->getInterfaceNames() as $interface) {
204-
if (isset(self::$deprecated[$interface]) && strncmp($ns, $interface, $len) && !($parent && $parent->implementsInterface($interface))) {
212+
if (isset(self::$deprecated[$interface]) && strncmp($ns, $interface, $len)) {
213+
$deprecatedInterfaces[] = $interface;
214+
}
215+
foreach (class_implements($interface) as $interface) {
216+
$parentInterfaces[$interface] = 1;
217+
}
218+
}
219+
220+
foreach ($deprecatedInterfaces as $interface) {
221+
if (!isset($parentInterfaces[$interface])) {
205222
@trigger_error(sprintf('The %s %s %s that is deprecated %s', $name, $refl->isInterface() ? 'interface extends' : 'class implements', $interface, self::$deprecated[$interface]), E_USER_DEPRECATED);
206223
}
207224
}

src/Symfony/Component/Debug/Tests/DebugClassLoaderTest.php

+24
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,28 @@ public function provideDeprecatedSuper()
203203
);
204204
}
205205

206+
public function testInterfaceExtendsDeprecatedInterface()
207+
{
208+
set_error_handler('var_dump', 0);
209+
$e = error_reporting(0);
210+
trigger_error('', E_USER_NOTICE);
211+
212+
class_exists('Test\\'.__NAMESPACE__.'\\NonDeprecatedInterfaceClass', true);
213+
214+
error_reporting($e);
215+
restore_error_handler();
216+
217+
$lastError = error_get_last();
218+
unset($lastError['file'], $lastError['line']);
219+
220+
$xError = array(
221+
'type' => E_USER_NOTICE,
222+
'message' => '',
223+
);
224+
225+
$this->assertSame($xError, $lastError);
226+
}
227+
206228
public function testDeprecatedSuperInSameNamespace()
207229
{
208230
set_error_handler('var_dump', 0);
@@ -289,6 +311,8 @@ public function findFile($class)
289311
eval('namespace Test\\'.__NAMESPACE__.'; class DeprecatedParentClass extends \\'.__NAMESPACE__.'\Fixtures\DeprecatedClass {}');
290312
} elseif ('Test\\'.__NAMESPACE__.'\DeprecatedInterfaceClass' === $class) {
291313
eval('namespace Test\\'.__NAMESPACE__.'; class DeprecatedInterfaceClass implements \\'.__NAMESPACE__.'\Fixtures\DeprecatedInterface {}');
314+
} elseif ('Test\\'.__NAMESPACE__.'\NonDeprecatedInterfaceClass' === $class) {
315+
eval('namespace Test\\'.__NAMESPACE__.'; class NonDeprecatedInterfaceClass implements \\'.__NAMESPACE__.'\Fixtures\NonDeprecatedInterface {}');
292316
} elseif ('Test\\'.__NAMESPACE__.'\Float' === $class) {
293317
eval('namespace Test\\'.__NAMESPACE__.'; class Float {}');
294318
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Symfony\Component\Debug\Tests\Fixtures;
4+
5+
interface NonDeprecatedInterface extends DeprecatedInterface
6+
{
7+
}

0 commit comments

Comments
 (0)