Skip to content

Commit

Permalink
bug #30363 Fixed the DebugClassLoader compatibility with eval()'d cod…
Browse files Browse the repository at this point in the history
…e 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
  • Loading branch information
nicolas-grekas committed Feb 24, 2019
2 parents 9202d9e + 6c2aa24 commit 20b5fb0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Symfony/Component/Debug/DebugClassLoader.php
Expand Up @@ -390,6 +390,11 @@ private function darwinRealpath($real)

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

if (!isset($dirFiles[$file]) && ') : eval()\'d code' === substr($file, -17)) {
// Get the file name from "file_name.php(123) : eval()'d code"
$file = substr($file, 0, strrpos($file, '(', -17));
}

if (isset($dirFiles[$file])) {
return $real .= $dirFiles[$file];
}
Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Component/Debug/Tests/DebugClassLoaderTest.php
Expand Up @@ -385,6 +385,11 @@ class_exists('Test\\'.__NAMESPACE__.'\\UseTraitWithInternalMethod', true);

$this->assertSame([], $deprecations);
}

public function testEvaluatedCode()
{
$this->assertTrue(class_exists(__NAMESPACE__.'\Fixtures\DefinitionInEvaluatedCode', true));
}
}

class ClassLoader
Expand Down
@@ -0,0 +1,11 @@
<?php

namespace Symfony\Component\Debug\Tests\Fixtures;

eval('
namespace Symfony\Component\Debug\Tests\Fixtures;
class DefinitionInEvaluatedCode
{
}
');

0 comments on commit 20b5fb0

Please sign in to comment.