Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d638237

Browse filesBrowse files
[Debug] fix detecting overriden final/internal methods implemented using traits
1 parent 8bc014c commit d638237
Copy full SHA for d638237

File tree

Expand file treeCollapse file tree

6 files changed

+35
-20
lines changed
Filter options
Expand file treeCollapse file tree

6 files changed

+35
-20
lines changed

‎src/Symfony/Component/Debug/DebugClassLoader.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Debug/DebugClassLoader.php
+9-11Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -247,25 +247,23 @@ private function checkClass($class, $file = null)
247247
continue;
248248
}
249249

250-
// Method from a trait
251-
if ($method->getFilename() !== $refl->getFileName()) {
252-
continue;
253-
}
254-
255250
if ($isClass && $parent && isset(self::$finalMethods[$parent][$method->name])) {
256251
list($declaringClass, $message) = self::$finalMethods[$parent][$method->name];
257252
@trigger_error(sprintf('The "%s::%s()" method is considered final%s. It may change without further notice as of its next major version. You should not extend it from "%s".', $declaringClass, $method->name, $message, $name), E_USER_DEPRECATED);
258253
}
259254

260-
foreach ($parentAndTraits as $use) {
261-
if (isset(self::$internalMethods[$use][$method->name])) {
262-
list($declaringClass, $message) = self::$internalMethods[$use][$method->name];
263-
if (\strncmp($ns, $declaringClass, $len)) {
264-
@trigger_error(sprintf('The "%s::%s()" method is considered internal%s. It may change without further notice. You should not extend it from "%s".', $declaringClass, $method->name, $message, $name), E_USER_DEPRECATED);
265-
}
255+
if (isset(self::$internalMethods[$name][$method->name])) {
256+
list($declaringClass, $message) = self::$internalMethods[$name][$method->name];
257+
if (\strncmp($ns, $declaringClass, $len)) {
258+
@trigger_error(sprintf('The "%s::%s()" method is considered internal%s. It may change without further notice. You should not extend it from "%s".', $declaringClass, $method->name, $message, $name), E_USER_DEPRECATED);
266259
}
267260
}
268261

262+
// Method from a trait
263+
if ($method->getFilename() !== $refl->getFileName()) {
264+
continue;
265+
}
266+
269267
// Detect method annotations
270268
if (false === $doc = $method->getDocComment()) {
271269
continue;

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Debug/Tests/DebugClassLoaderTest.php
+6-9Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -312,24 +312,21 @@ class_exists('Test\\'.__NAMESPACE__.'\\ExtendsFinalClass', true);
312312

313313
public function testExtendedFinalMethod()
314314
{
315-
set_error_handler(function () { return false; });
316-
$e = error_reporting(0);
317-
trigger_error('', E_USER_NOTICE);
315+
$deprecations = array();
316+
set_error_handler(function ($type, $msg) use (&$deprecations) { $deprecations[] = $msg; });
317+
$e = error_reporting(E_USER_DEPRECATED);
318318

319319
class_exists(__NAMESPACE__.'\\Fixtures\\ExtendedFinalMethod', true);
320320

321321
error_reporting($e);
322322
restore_error_handler();
323323

324-
$lastError = error_get_last();
325-
unset($lastError['file'], $lastError['line']);
326-
327324
$xError = array(
328-
'type' => E_USER_DEPRECATED,
329-
'message' => 'The "Symfony\Component\Debug\Tests\Fixtures\FinalMethod::finalMethod()" method is considered final since version 3.3. It may change without further notice as of its next major version. You should not extend it from "Symfony\Component\Debug\Tests\Fixtures\ExtendedFinalMethod".',
325+
'The "Symfony\Component\Debug\Tests\Fixtures\FinalMethod::finalMethod()" method is considered final since version 3.3. It may change without further notice as of its next major version. You should not extend it from "Symfony\Component\Debug\Tests\Fixtures\ExtendedFinalMethod".',
326+
'The "Symfony\Component\Debug\Tests\Fixtures\FinalMethod::finalMethod2()" method is considered final. It may change without further notice as of its next major version. You should not extend it from "Symfony\Component\Debug\Tests\Fixtures\ExtendedFinalMethod".',
330327
);
331328

332-
$this->assertSame($xError, $lastError);
329+
$this->assertSame($xError, $deprecations);
333330
}
334331

335332
public function testExtendedDeprecatedMethodDoesntTriggerAnyNotice()

‎src/Symfony/Component/Debug/Tests/Fixtures/ExtendedFinalMethod.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Debug/Tests/Fixtures/ExtendedFinalMethod.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
class ExtendedFinalMethod extends FinalMethod
66
{
7+
use FinalMethod2Trait;
8+
79
/**
810
* {@inheritdoc}
911
*/

‎src/Symfony/Component/Debug/Tests/Fixtures/FinalMethod.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Debug/Tests/Fixtures/FinalMethod.php
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ public function finalMethod()
1111
{
1212
}
1313

14+
/**
15+
* @final
16+
*/
17+
public function finalMethod2()
18+
{
19+
}
20+
1421
public function anotherMethod()
1522
{
1623
}
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace Symfony\Component\Debug\Tests\Fixtures;
4+
5+
trait FinalMethod2Trait
6+
{
7+
public function finalMethod2()
8+
{
9+
}
10+
}

‎src/Symfony/Component/Debug/Tests/phpt/debug_class_loader.phpt

Copy file name to clipboardExpand all lines: src/Symfony/Component/Debug/Tests/phpt/debug_class_loader.phpt
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ class_exists(ExtendedFinalMethod::class);
2424
?>
2525
--EXPECTF--
2626
The "Symfony\Component\Debug\Tests\Fixtures\FinalMethod::finalMethod()" method is considered final since version 3.3. It may change without further notice as of its next major version. You should not extend it from "Symfony\Component\Debug\Tests\Fixtures\ExtendedFinalMethod".
27+
The "Symfony\Component\Debug\Tests\Fixtures\FinalMethod::finalMethod2()" method is considered final. It may change without further notice as of its next major version. You should not extend it from "Symfony\Component\Debug\Tests\Fixtures\ExtendedFinalMethod".

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.