8000 bug #30363 Fixed the DebugClassLoader compatibility with eval()'d cod… · symfony/symfony@20b5fb0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 20b5fb0

Browse files
bug #30363 Fixed the DebugClassLoader compatibility with eval()'d code on Darwin (skalpa)
This PR was squashed before being merged into the 3.4 branch (closes #30363). Discussion ---------- Fixed the DebugClassLoader compatibility with eval()'d code on Darwin | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #30362 | License | MIT When a class is defined in an `eval()` block, the reported file name is `file_name.php(123) : eval()'d code`, which prevents `DebugClassLoader::darwinRealpath()` from locating/normalizing the file name, and triggers a notice. Commits ------- 6c2aa24 Fixed the DebugClassLoader compatibility with eval()'d code on Darwin
2 parents 9202d9e + 6c2aa24 commit 20b5fb0

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

src/Symfony/Component/Debug/DebugClassLoader.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,11 @@ private function darwinRealpath($real)
390390

391391
$dirFiles = self::$darwinCache[$kDir][1];
392392

393+
if (!isset($dirFiles[$file]) && ') : eval()\'d code' === substr($file, -17)) {
394+
// Get the file name from "file_name.php(123) : eval()'d code"
395+
$file = substr($file, 0, strr 8000 pos($file, '(', -17));
396+
}
397+
393398
if (isset($dirFiles[$file])) {
394399
return $real .= $dirFiles[$file];
395400
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,11 @@ class_exists('Test\\'.__NAMESPACE__.'\\UseTraitWithInternalMethod', true);
385385

386386
$this->assertSame([], $deprecations);
387387
}
388+
389+
public function testEvaluatedCode()
390+
{
391+
$this->assertTrue(class_exists(__NAMESPACE__.'\Fixtures\DefinitionInEvaluatedCode', true));
392+
}
388393
}
389394

390395
class ClassLoader
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Symfony\Component\Debug\Tests\Fixtures;
4+
5+
eval('
6+
namespace Symfony\Component\Debug\Tests\Fixtures;
7+
8+
class DefinitionInEvaluatedCode
9+
{
10+
}
11+
');

0 commit comments

Comments
 (0)
0