Skip to content

Commit 56987ea

Browse files
committed
bug #23989 [Debug] Remove false-positive check in DebugClassLoader (nicolas-grekas)
This PR was merged into the 2.7 branch. Discussion ---------- [Debug] Remove false-positive check in DebugClassLoader | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #23977 | License | MIT | Doc PR | - In some edge case situations, DebugClassLoader generates false-positives (see linked issue, ping @gharlan). Commits ------- 466da3f [Debug] Remove false-positive check in DebugClassLoader
2 parents c896664 + 466da3f commit 56987ea

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

src/Symfony/Component/Debug/DebugClassLoader.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class DebugClassLoader
2626
{
2727
private $classLoader;
2828
private $isFinder;
29+
private $loaded = array();
2930
private $wasFinder;
3031
private static $caseCheck;
3132
private static $deprecated = array();
@@ -164,9 +165,10 @@ public function loadClass($class)
164165
ErrorHandler::stackErrors();
165166

166167
try {
167-
if ($this->isFinder) {
168+
if ($this->isFinder && !isset($this->loaded[$class])) {
169+
$this->loaded[$class] = true;
168170
if ($file = $this->classLoader[0]->findFile($class)) {
169-
require_once $file;
171+
require $file;
170172
}
171173
} else {
172174
call_user_func($this->classLoader, $class);

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,23 @@ public function testIdempotence()
5959
$this->fail('DebugClassLoader did not register');
6060
}
6161

62+
/**
63+
* @expectedException \Exception
64+
* @expectedExceptionMessage boo
65+
*/
66+
public function testThrowingClass()
67+
{
68+
try {
69+
class_exists(__NAMESPACE__.'\Fixtures\Throwing');
70+
$this->fail('Exception expected');
71+
} catch (\Exception $e) {
72+
$this->assertSame('boo', $e->getMessage());
73+
}
74+
75+
// the second call also should throw
76+
class_exists(__NAMESPACE__.'\Fixtures\Throwing');
77+
}
78+
6279
public function testUnsilencing()
6380
{
6481
if (\PHP_VERSION_ID >= 70000) {
@@ -128,6 +145,7 @@ class ChildTestingStacking extends TestingStacking { function foo($bar) {} }
128145

129146
/**
130147
* @expectedException \RuntimeException
148+
* @expectedExceptionMessage Case mismatch between loaded and declared class names
131149
*/
132150
public function testNameCaseMismatch()
133151
{
@@ -149,6 +167,7 @@ class_exists(__NAMESPACE__.'\Fixtures\CaseMismatch', true);
149167

150168
/**
151169
* @expectedException \RuntimeException
170+
* @expectedExceptionMessage Case mismatch between loaded and declared class names
152171
*/
153172
public function testPsr4CaseMismatch()
154173
{
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+
throw new \Exception('boo');

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy