-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Code inside eval
triggers deprecation, results in ExcludeList::isExcluded(): Argument #1 ($file) must be of type string, null given
#6043
Comments
Thank you for your report. Please provide a minimal, self-contained, reproducing test case that shows the problem you are reporting. Without such a minimal, self-contained, reproducing test case I will not be able to investigate this issue. |
I'm sorry, but I'm having a really hard time coming up with a minimal, self-contained, reproducing test case. Any advice? |
I am able to create a test that triggers a deprecation. But I cannot mimic the scenario that happens with Twig. Twig uses But even with this, I always receive the final class Test extends TestCase
{
public static function testEval(): void
{
$code = <<<'PHP'
function main() {
yield fn() => \PHPUnit\TestFixture\Bug6043\trigger_deprecation('deprecation triggered from within eval', E_USER_DEPRECATED);
}
foreach (main() as $item) {
echo $item();
}
PHP;
eval($code);
}
} |
The example given in #6043 (comment) is not self-contained, as it uses a function named I have changed the example to make it run like so: <?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
final class Test extends TestCase
{
public function testEval(): void
{
$code = <<<'PHP'
function main() {
yield fn() => trigger_error('message', E_USER_DEPRECATED);
}
foreach (main() as $item) {
$item();
}
PHP;
eval($code);
$this->assertTrue(true);
}
} With the above, I get
This looks correct to me, but you mentioned that "even with this, [you] always receive the I implemented a safe guard to not use the Please let me know whether this solves the issue for you. Thanks! |
I just ran the Twig suite on latest phpunit main again and can confirm the problem is gone now. Thanks for the fast fix and pointing out the problem that I was using the dev dependency without knowing it. |
Summary
When
eval
'd code triggers a deprecation, the following error happens:Current behavior
This was introduced in 5d6dc50#diff-c59b939cd44edcda5d8a71c38f90461826dc2abbb5267f343fd7db0fa8fe1784
phpunit/src/Runner/ErrorHandler.php
Lines 403 to 405 in dac4a5f
Here, it should handle the fact that
file
cannot be there.How to reproduce
PR where the issue is visible: twigphp/Twig#4472
When running the debugger, you can see that
file
is not part of the stack trace frame when the code is eval'd.Expected behavior
No error.
The text was updated successfully, but these errors were encountered: