Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 90e7945

Browse files
bug #28411 [Debug] fix detecting overriden final/internal methods implemented using traits (nicolas-grekas)
This PR was merged into the 3.4 branch. Discussion ---------- [Debug] fix detecting overriden final/internal methods implemented using traits | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Commits ------- d638237 [Debug] fix detecting overriden final/internal methods implemented using traits
2 parents be05bbf + d638237 commit 90e7945

File tree

6 files changed

+35
-20
lines changed

6 files changed

+35
-20
lines changed

src/Symfony/Component/Debug/DebugClassLoader.php

Lines 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

Lines 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

Lines 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

Lines 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
}
Lines 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

Lines 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)