Skip to content

Normalize __DIR__ and __FILE__ by changing the base path of LocatedSource instances, prevent false-positive BC breaks on those magic constants #476

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

Conversation

Ocramius
Copy link
Member

@Ocramius Ocramius commented Mar 8, 2022

This fails due to CompileNodeToValue() internally using realpath() and dirname() operations, which both depend
on the current filesystem: as it currently stands, this requires an improvement of roave/better-reflection first.

Also, ReplaceSourcePathOfLocatedSources and LocatedSourceWithStrippedSourcesDirectory are extending @internal
symbols, so we may want to first make these symbols public in roave/better-reflection, to avoid the BC boundary to
become too relaxed, and therefore causing crashes if we (rightfully) decide to change roave/better-reflection internals.

Fixes #400
Fixes #410

TODO

…the base path of `LocatedSource` instances

This fails due to `CompileNodeToValue()` internally using `realpath()` and `dirname()` operations, which both depend
on the current filesystem: as it currently stands, this requires an improvement of `roave/better-reflection` first.

Also, `ReplaceSourcePathOfLocatedSources` and `LocatedSourceWithStrippedSourcesDirectory` are extending `@internal`
symbols, so we may want to first make these symbols public in `roave/better-reflection`, to avoid the BC boundary to
become too relaxed, and therefore causing crashes if we (rightfully) decide to change `roave/better-reflection` internals.

Fixes #400
Fixes #410
This contains Roave/BetterReflection#1043, which allows us to use `__DIR__` and `__FILE__`
even if the real file locations were omitted/changed by the source locator.
…placeSourcePathOfLocatedSources`

This goes in great detail to test every corner of these hacky overrides, making sure that we don't
accidentally introduce incompatibilities with the parent implementation, since we have to use inheritance
for this design.
@Ocramius Ocramius force-pushed the fix/#400-#410-normalize-source-paths-to-prevent-__DIR__-and-__FILE__-bc-break-false-positives branch from dd3e94b to b124173 Compare March 22, 2022 17:49
@Ocramius Ocramius removed the WIP label Mar 22, 2022
@Ocramius Ocramius requested a review from asgrim March 22, 2022 17:52
@Ocramius
Copy link
Member Author

@asgrim this is (IMO) ready for review

@Ocramius Ocramius changed the title Prototype: attempt to normalize __DIR__ and __FILE__ by changing the base path of LocatedSource instances Normalize __DIR__ and __FILE__ by changing the base path of LocatedSource instances Mar 22, 2022
@Ocramius Ocramius changed the title Normalize __DIR__ and __FILE__ by changing the base path of LocatedSource instances Normalize __DIR__ and __FILE__ by changing the base path of LocatedSource instances, prevent false-positive BC breaks on those magic constants Mar 22, 2022
Copy link
Member

@asgrim asgrim left a comment

Choose a reason for hiding this comment

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

Yeah this is much cleaner - looks like it was a bit of a journey to get here though heh. Nice one 👍

@Ocramius
Copy link
Member Author

🚢 then, thanks for the review, @asgrim!

@Ocramius Ocramius merged commit 2e51abb into 6.3.x Mar 23, 2022
@Ocramius Ocramius deleted the fix/#400-#410-normalize-source-paths-to-prevent-__DIR__-and-__FILE__-bc-break-false-positives branch March 23, 2022 15:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

False positive result when __DIR__ is used
2 participants