Skip to content

Commit

Permalink
[Debug] Deprecations exception for Symfony internals
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Feb 23, 2015
1 parent 4fd9792 commit 323e957
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
20 changes: 16 additions & 4 deletions src/Symfony/Component/Debug/DebugClassLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,16 +180,28 @@ public function loadClass($class)
if (preg_match('#\n \* @deprecated (.*?)\r?\n \*(?: @|/$)#s', $refl->getDocComment(), $notice)) {
self::$deprecated[$name] = preg_replace('#\s*\r?\n \* +#', ' ', $notice[1]);
} else {
$len = 1 + (strpos($name, '\\', 1 + strpos($name, '\\')) ?: strpos($name, '_'));
if (2 > $len = 1 + (strpos($name, '\\', 1 + strpos($name, '\\')) ?: strpos($name, '_'))) {
$len = 0;
$ns = '';
} else {
switch ($ns = substr($name, 0, $len)) {
case 'Symfony\Bridge\\':
case 'Symfony\Bundle\\':
case 'Symfony\Component\\':
$ns = 'Symfony\\';
$len = strlen($ns);
break;
}
}
$parent = $refl->getParentClass();

if (!$parent || $len < 2 || strncmp($name, $parent, $len)) {
if ($parent && isset(self::$deprecated[$parent->name]) && ($len < 2 || strncmp($name, $parent->name, $len))) {
if (!$parent || strncmp($ns, $parent, $len)) {

This comment has been minimized.

Copy link
@userfriendly

userfriendly Apr 20, 2015

Contributor

Passing $parent instead of e.g. $parent->name to strncmp() here seems to break the APY/DataGridBundle for us. Not sure about the side effects of changing this, so would like feedback before submitting a PR.

This comment has been minimized.

Copy link
@nicolas-grekas

nicolas-grekas Apr 20, 2015

Author Member

Please open the PR, using $parent->name is better

This comment has been minimized.

Copy link
@userfriendly

userfriendly Apr 20, 2015

Contributor

Cheers, PR is here: #14422

if ($parent && isset(self::$deprecated[$parent->name]) && strncmp($ns, $parent->name, $len)) {
trigger_error(sprintf('The %s class extends %s that is deprecated %s', $name, $parent->name, self::$deprecated[$parent->name]), E_USER_DEPRECATED);
}

foreach ($refl->getInterfaceNames() as $interface) {
if (isset(self::$deprecated[$interface]) && ($len < 2 || strncmp($name, $interface, $len)) && !($parent && $parent->implementsInterface($interface))) {
if (isset(self::$deprecated[$interface]) && strncmp($ns, $interface, $len) && !($parent && $parent->implementsInterface($interface))) {
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);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Component/Debug/Tests/DebugClassLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public function testDeprecatedSuperInSameNamespace()
$e = error_reporting(0);
trigger_error('', E_USER_NOTICE);

class_exists(__NAMESPACE__.'\Fixtures\ExtendsDeprecatedParent', true);
class_exists('Symfony\Bridge\Debug\Tests\Fixtures\ExtendsDeprecatedParent', true);

error_reporting($e);
restore_error_handler();
Expand Down Expand Up @@ -239,8 +239,8 @@ public function findFile($class)
return __DIR__.'/Fixtures/notPsr0Bis.php';
} elseif (__NAMESPACE__.'\Fixtures\DeprecatedInterface' === $class) {
return __DIR__.'/Fixtures/DeprecatedInterface.php';
} elseif (__NAMESPACE__.'\Fixtures\ExtendsDeprecatedParent' === $class) {
eval('namespace '.__NAMESPACE__.'\Fixtures; class ExtendsDeprecatedParent extends DeprecatedClass {}');
} elseif ('Symfony\Bridge\Debug\Tests\Fixtures\ExtendsDeprecatedParent' === $class) {
eval('namespace Symfony\Bridge\Debug\Tests\Fixtures; class ExtendsDeprecatedParent extends \\'.__NAMESPACE__.'\Fixtures\DeprecatedClass {}');
} elseif ('Test\\'.__NAMESPACE__.'\DeprecatedParentClass' === $class) {
eval('namespace Test\\'.__NAMESPACE__.'; class DeprecatedParentClass extends \\'.__NAMESPACE__.'\Fixtures\DeprecatedClass {}');
} elseif ('Test\\'.__NAMESPACE__.'\DeprecatedInterfaceClass' === $class) {
Expand Down

0 comments on commit 323e957

Please sign in to comment.