Skip to content
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

Fix filemtime() warning because of eval'd code #494

Merged
merged 6 commits into from
Sep 5, 2024

Conversation

andrey-tech
Copy link
Contributor

Q A
Branch? 1.14.x
Bug fix? yes
New feature? no
Deprecations? no
Ticket Fix #492
License MIT
Doc PR -

Description

This small PR fix the old problem "filemtime() warning on eval'd code" described in issue #492 and in PR #436.

I faced this bug in my current big project when upgrading PHP from 8.1 to 8.2. But I can't migrate away from doctrine/annotations and use attributes just now. So, please, check and accept this PR ASAP. Thank you!

@derrabus
Copy link
Member

derrabus commented Sep 5, 2024

So, please, check and accept this PR ASAP. Thank you!

I appreciate your contribution and I believe that your bugfix is legit. But if you allow me, a little advice for the future: If you want people you don't have any SLAs with to help you in their freetime, please avoid the term "ASAP" in your request.

@@ -229,7 +230,7 @@ private function getLastModification(ReflectionClass $class): int
$parent = $class->getParentClass();

$lastModification = max(array_merge(
[$filename ? filemtime($filename) : 0],
[is_file($filename) ? filemtime($filename) : 0],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$filename is whatever ReflectionClass::getFileName() returns and that could technically be false. I don't want to pass false to is_file().

Suggested change
[is_file($filename) ? filemtime($filename) : 0],
[$filename !== false && is_file($filename) ? filemtime($filename) : 0],

That being said, what actually does $filename contain in case of a class that comes from eval'ed code? 🤔

Copy link
Contributor Author

@andrey-tech andrey-tech Sep 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Thank you for fast answer and support!
  2. You are absolutely right, I added check $filename !== false.
  3. That being said, what actually does $filename contain in case of a class that comes from eval'ed code?

The filename contains something like (see Issue #432): /home/.../my-project/vendor/lexik/jwt-authentication-bundle/Security/Authenticator/ForwardCompatAuthenticatorTrait.php(14) : eval()'d code.

In PHPUnit test case filename contains /.../tests/Doctrine/Tests/Common/Annotations/PsrCachedReaderTest.php(236) : eval()'d code.

@@ -220,6 +220,28 @@ public function testReaderIsNotHitIfCacheIsFresh(): void
);
}

public function testReaderDoesNotCacheIfFileDoesNotExistSoLastModificationCannotBeDetermined(): void
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice test. Can you please repeat this test for the CachedReader as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New test added.

@derrabus derrabus added the bug label Sep 5, 2024
@derrabus derrabus added this to the 1.14.4 milestone Sep 5, 2024
@derrabus
Copy link
Member

derrabus commented Sep 5, 2024

I think, you need to pick a different class names and/or namespaces in the two eval'ed snippets.

@andrey-tech
Copy link
Contributor Author

I think, you need to pick a different class names and/or namespaces in the two eval'ed snippets.

I set a different class names in the two eval'ed snippets.

@derrabus
Copy link
Member

derrabus commented Sep 5, 2024

Your new test is failing on PHP 7.1 now.

@derrabus
Copy link
Member

derrabus commented Sep 5, 2024

Let me take this over. Nobody should have to debug stuff on PHP 7.1 anymore these days. 🙈

@derrabus derrabus merged commit 253dca4 into doctrine:1.14.x Sep 5, 2024
15 checks passed
@derrabus
Copy link
Member

derrabus commented Sep 5, 2024

Thank you very much!

derrabus added a commit to derrabus/annotations that referenced this pull request Sep 5, 2024
* 1.14.x:
  Fix filemtime() warning because of eval'd code (doctrine#494)
  Test with Symfony Cache 7 (doctrine#499)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants