8000 [Debug] Remove false-positive deprecation from DebugClassLoader by nicolas-grekas · Pull Request #24921 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
8000

[Debug] Remove false-positive deprecation from DebugClassLoader #24921

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions src/Symfony/Component/Debug/DebugClassLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class DebugClassLoader
private static $final = array();
private static $finalMethods = array();
private static $deprecated = array();
private static $deprecatedMethods = array();
private static $internal = array();
private static $internalMethods = array();
private static $php7Reserved = array('int', 'float', 'bool', 'string', 'true', 'false', 'null');
Expand Down Expand Up @@ -204,12 +203,11 @@ public function loadClass($class)
}
}

// Inherit @final and @deprecated annotations for methods
// Inherit @final and @internal annotations for methods
self::$finalMethods[$name] = array();
self::$deprecatedMethods[$name] = array();
self::$internalMethods[$name] = array();
foreach ($parentAndTraits as $use) {
foreach (array('finalMethods', 'deprecatedMethods', 'internalMethods') as $property) {
foreach (array('finalMethods', 'internalMethods') as $property) {
if (isset(self::${$property}[$use])) {
self::${$property}[$name] = array_merge(self::${$property}[$name], self::${$property}[$use]);
}
Expand All @@ -233,12 +231,6 @@ public function loadClass($class)
}

foreach ($parentAndTraits as $use) {
if (isset(self::$deprecatedMethods[$use][$method->name])) {
list($declaringClass, $message) = self::$deprecatedMethods[$use][$method->name];
if (strncmp($ns, $declaringClass, $len)) {
@trigger_error(sprintf('The "%s::%s()" method is deprecated%s. You should not extend it from "%s".', $declaringClass, $method->name, $message, $name), E_USER_DEPRECATED);
}
}
if (isset(self::$internalMethods[$use][$method->name])) {
list($declaringClass, $message) = self::$internalMethods[$use][$method->name];
if (strncmp($ns, $declaringClass, $len)) {
Expand All @@ -252,7 +244,7 @@ public function loadClass($class)
continue;
}

foreach (array('final', 'deprecated', 'internal') as $annotation) {
foreach (array('final', 'internal') as $annotation) {
if (false !== strpos($doc, '@'.$annotation) && preg_match('#\n\s+\* @'.$annotation.'(?:( .+?)\.?)?\r?\n\s+\*(?: @|/$)#s', $doc, $notice)) {
$message = isset($notice[1]) ? preg_replace('#\s*\r?\n \* +#', ' ', $notice[1]) : '';
self::${$annotation.'Methods'}[$name][$method->name] = array($name, $message);
Expand Down
9 changes: 2 additions & 7 deletions src/Symfony/Component/Debug/Tests/DebugClassLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ class_exists(__NAMESPACE__.'\\Fixtures\\ExtendedFinalMethod', true);
$this->assertSame($xError, $lastError);
}

public function testExtendedDeprecatedMethod()
public function testExtendedDeprecatedMethodDoesntTriggerAnyNotice()
{
set_error_handler(function () { return false; });
$e = error_reporting(0);
Expand All @@ -346,12 +346,7 @@ class_exists('Test\\'.__NAMESPACE__.'\\ExtendsAnnotatedClass', true);
$lastError = error_get_last();
unset($lastError['file'], $lastError['line']);

$xError = array(
'type' => E_USER_DEPRECATED,
'message' => 'The "Symfony\Component\Debug\Tests\Fixtures\AnnotatedClass::deprecatedMethod()" method is deprecated since version 3.4. You should not extend it from "Test\Symfony\Component\Debug\Tests\ExtendsAnnotatedClass".',
);

$this->assertSame($xError, $lastError);
$this->assertSame(array('type' => E_USER_NOTICE, 'message' => ''), $lastError);
}

public function testInternalsUse()
Expand Down
0