Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
PHP 8.0 is stricter about argument types and throws an error when fopen() is called with a $path === FALSE in \Drupal\Core\StreamWrapper\LocalStream::stream_open()
Steps to reproduce
Run tests on PHP 8.0 - see https://www.drupal.org/pift-ci-job/1855374
$ php7 -r 'var_dump(fopen(FALSE, "r"));'
...
Warning: fopen(): Filename cannot be empty in Command line code on line 1
$ php8 -r 'var_dump(fopen(FALSE, "r"));'
...
Fatal error: Uncaught ValueError: Path cannot be empty in Command line code on line 1
Proposed resolution
Get $path value and return early.
Remaining tasks
review/commit
User interface changes
None
API changes
None
Data model changes
None
Release notes snippet
N/a
Comment | File | Size | Author |
---|---|---|---|
#27 | 3177541-7.x-reroll.patch | 770 bytes | swim |
#14 | 3177541-12.patch | 825 bytes | alexpott |
#14 | 8-12-interdiff.txt | 777 bytes | alexpott |
Comments
Comment #2
alexpottComment #3
andypostWould be great to add inline comment otherwise rtbc+1
Comment #4
alexpott@andypost this really does not need an inline comment - how can fopen open a path that is FALSE?
Comment #5
andypostupdated IS with steps to reproduce -
$filename
is required nowComment #6
andypostBetter example
Comment #7
andypostfix php8 cli
Comment #8
andypost@alexpott kind of this coment
Comment #9
andypostThe only case documented is
\Drupal\Core\StreamWrapper\LocalStream::getLocalPath()
's return valueBtw BC affected with current patch - before it
STREAM_REPORT_ERRORS
allowed to catch error to calling code and react, now just FALSE returnedComment #10
alexpott@andypost that's a comment that will have to be removed once PHP 8 is the minimum supported version. I'd argue that this comment helps no one.
Comment #11
alexpottGood point on BC. We can be inspired by \Drupal\Core\StreamWrapper\LocalReadOnlyStream::stream_open() and do the same.
Comment #12
andypostis strict comparison, the question is why that instead of
if (!$path) {
Comment #13
andypostphp -r 'var_dump(fopen("", "r"));'
also fatal error nowComment #14
alexpottHere we go. Removing comment added in #8 because it really will only have to be removed in Drupal 10 and we'll forgot to do that. And it serves no purpose.
I guess we now need to find a place to test this.
Comment #15
alexpottRe #12 @andypost how does \Drupal\Core\StreamWrapper\LocalStream::getLocalPath() return an empty string?
Comment #16
alexpottI looked for test coverage of the local stream wrapper but there is only implicit test coverage - because it is used everywhere :) - we know the implicit coverage exists because the PHP 8 test run failed because of this.
Comment #17
andypostI think no tests needed too, but curious about hiding error - should we add follow-up or not?
I think "report errors" should not prevent fatal errors on PHP 8 when it become minimally required, could use todo and follow-up
Comment #18
alexpott@andypost well this is maintaining the current behaviour of returning FALSE in this case. Which we're relying on in FileSystemRequirementsTest as per the test run.
Comment #19
andypostFiled follow-up #3178994: Allow fatal error on PHP 8.0 in LocalStream::stream_open() for fopen()
is code duplication
($options & STREAM_REPORT_ERRORS)
fine here?Comment #20
alexpottIt's not really code duplication - since we have to check this in both places to maintain current behaviour regardless of PHP version.
Comment #21
andypostThen it ready for commiters! Thank you
Comment #24
catchI think this is good for PHP 8 compatibility and thanks for opening the Drupal 10 follow-up.
Committed/pushed to 9.2.x and cherry-picked to 9.1.x.
Comment #26
andypost@alexpott follow-up is ready for review #3178994-14: Allow fatal error on PHP 8.0 in LocalStream::stream_open() for fopen()
Comment #27
swim CreditAttribution: swim commentedFor those lucky enough to still be dealing with 7; here's a reroll against 7.x
Comment #28
dsnopekComment #29
cafuego CreditAttribution: cafuego at United Nations commentedThat reroll patch, when applied, seems to turn a logged PHP error into a segmentation fault without further logs :-)
Comment #30
andypost@cafuego tbis issue for 9.x the 7.x one is #3273723: fopen() error in stream_wrappers.inc on PHP 8