Skip to content

Fix GH-9883 SplFileObject::__toString() reads next line #9912

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

Closed
wants to merge 1 commit into from

Conversation

Girgias
Copy link
Member

@Girgias Girgias commented Nov 9, 2022

We need to overwrite the __toString magic method for SplFileObject, similarly to how DirectoryIterator overwrites it Moreover, the custom cast handler is useless as we define __toString methods, so use the standard one instead.

@Girgias Girgias requested a review from cmb69 November 9, 2022 15:24
@Girgias Girgias changed the base branch from master to PHP-8.0 November 9, 2022 15:25
@Girgias Girgias closed this Nov 9, 2022
@Girgias Girgias reopened this Nov 9, 2022
Copy link
Member

@arnaud-lb arnaud-lb left a comment

Choose a reason for hiding this comment

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

Looks good to me

The documentation of __toString() will need to be changed as well

Copy link
Member

@cmb69 cmb69 left a comment

Choose a reason for hiding this comment

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

Thank you!

@cmb69
Copy link
Member

cmb69 commented Nov 11, 2022

I'm not sure if it makes any sense to target PHP-8.0; there may be no further regular bug fix release. But even if, it might be too risky that late in the release cycle (especially given that the bug is there for years).

@Girgias
Copy link
Member Author

Girgias commented Nov 15, 2022

I'm not sure if it makes any sense to target PHP-8.0; there may be no further regular bug fix release. But even if, it might be too risky that late in the release cycle (especially given that the bug is there for years).

Should I change the branch to 8.1 then? or also leave 8.1 alone and only target 8.2?

@cmb69
Copy link
Member

cmb69 commented Nov 16, 2022

Should I change the branch to 8.1 then? or also leave 8.1 alone and only target 8.2?

Depends on how certain we can be that this doesn't break existing code. I tend to think that it's good for 8.1.

We need to overwrite the __toString magic method for SplFileObject, similarly to how DirectoryIterator overwrites it
Moreover, the custom cast handler is useless as we define __toString methods, so use the standard one instead.
Copy link
Member

@cmb69 cmb69 left a comment

Choose a reason for hiding this comment

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

Thank you!

<?php
$file_stream = new SplFileObject(__FILE__, 'rb');

echo $file_stream; // line 4
Copy link
Contributor

Choose a reason for hiding this comment

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

Why such comments? I would remove them.

Copy link
Member

Choose a reason for hiding this comment

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

See #9883. The comments helped to identify what was going on, and may be helpful if something breaks (again) in the future.

@Girgias Girgias closed this in 6fbf81c Nov 22, 2022
@Girgias Girgias deleted the fix-gh9883 branch November 22, 2022 12:35
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.

4 participants