Skip to content

Conversation

@ndossche
Copy link
Member

@ndossche ndossche commented May 5, 2024

While it is possible to return a custom SplFileInfo object in the
iterator used by buildFromIterator(), the data is not actually used from
that object, instead the data from the underlying internal structure is
used. This makes it impossible to override some metadata such as the
path name and modification time.

The main motivation comes from two reasons:

  • Consistency. We expect our custom methods to be called when having a
    custom object.
  • Support reproducibility. This is the original use case as requested in
    [1].

Add support for this by calling the getMTime() and getPathname() methods
if they're overriden by a user class.

[1] theseer/Autoload#114.

@theseer
Copy link
Contributor

theseer commented Nov 25, 2025

Any progress planned for this here actually? :-)

@ndossche
Copy link
Member Author

This needs a strong rebase. But this should work.
Regardless of any new functionality added for reproducibility, it's good to be able to override these methods: the situation now where the override is ignored is not good.
I'll try to rebase this and check again tomorrow.

@ndossche
Copy link
Member Author

This is now rebased, with extra tests, and with some cleanups+fixes.
I'll re-check this tomorrow.

This is only a part of the reproducibility journey. It allows to override the builtin classes' behaviour, which you could argue is a bugfix.

@ndossche ndossche force-pushed the phar-fileinfo branch 2 times, most recently from 8752a73 to ac8f782 Compare December 6, 2025 10:21
While it is possible to return a custom SplFileInfo object in the
iterator used by buildFromIterator(), the data is not actually used from
that object, instead the data from the underlying internal structure is
used. This makes it impossible to override some metadata such as the
path name and modification time.

The main motivation comes from two reasons:
- Consistency. We expect our custom methods to be called when having a
  custom object.
- Support reproducibility. This is the original use case as requested in
  [1].

Add support for this by calling the getMTime() and getPathname() methods
if they're overriden by a user class.

[1] theseer/Autoload#114.
@ndossche ndossche marked this pull request as ready for review December 6, 2025 12:01
@ndossche
Copy link
Member Author

ndossche commented Dec 6, 2025

I believe this is ready for review. After this is merged I'll work on additional methods on ext/phar for setting timestamps etc directly.

@ndossche ndossche requested a review from Girgias December 6, 2025 12:01
zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0, "Could not resolve file path");
return ZEND_HASH_APPLY_STOP;
if (UNEXPECTED(Z_TYPE(rv) != IS_STRING)) {
zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0, "getPathname() must return a string");
Copy link
Member

Choose a reason for hiding this comment

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

This probably should be a type error, but I think there are other such problems in ext/phar so I'm happy to defer this to a latter PR.


fname_len = strlen(fname);
save = fname;
goto phar_spl_fileinfo;
Copy link
Member

Choose a reason for hiding this comment

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

I guess a follow-up refactoring is to get rid of this goto and assign the fname var in the corresponding switch case statement. As the GitHub UI didn't show me the label iniitally...

@ndossche ndossche merged commit c9008f6 into php:master Dec 13, 2025
10 checks passed
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.

3 participants