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
Upon update to php 8, the site started throwing an error on line 408. I'm sure this is related to PHP 8 not being very happy about potential null values. The following change stopped the error.
diff --git a/docroot/includes/stream_wrappers.inc b/docroot/includes/stream_wrappers.inc
index 31101674..f67ab42e 100644
--- a/docroot/includes/stream_wrappers.inc
+++ b/docroot/includes/stream_wrappers.inc
@@ -405,7 +405,11 @@ abstract class DrupalLocalStreamWrapper implements DrupalStreamWrapperInterface
public function stream_open($uri, $mode, $options, &$opened_path) {
$this->uri = $uri;
$path = $this->getLocalPath();
- $this->handle = ($options & STREAM_REPORT_ERRORS) ? fopen($path, $mode) : @fopen($path, $mode);
+ if ($path){
+ $this->handle = ($options & STREAM_REPORT_ERRORS) ? fopen($path, $mode) : @fopen($path, $mode);
+ } else {
+ return FALSE;
+ }
if ((bool) $this->handle && $options & STREAM_USE_PATH) {
$opened_path = $path;
Comments
Comment #2
cilefen CreditAttribution: cilefen commentedWhat is the error?
Comment #3
djdevinError is
ValueError: Path cannot be empty in fopen() (line 408 of /vagrant/www/ethos7/includes/stream_wrappers.inc).
Guess this is the D7 ticket, already fixed in related issues for D8/D9.
Here is a patch which is just loopy1492's changes (and are exactly the D9+ changes).
Comment #4
loopy1492 CreditAttribution: loopy1492 commentedThanks, @djdevin! I appreciate it. I actually got it fixed and forgot to take note of the error text. Haha.
Comment #5
mb_lewis CreditAttribution: mb_lewis at Milton Bayer commentedPatch applied cleanly and resolved the issue, moving to RTBC.
Comment #6
poker10 CreditAttribution: poker10 at ActivIT s.r.o. commentedAdded this to a list of PHP 8 issues.
Comment #7
HitchShock+1 RTBC, it works on customer sites as well
Comment #8
mcdruidThanks, looks like a straight backport of https://git.drupalcode.org/project/drupal/-/commit/fc7d4a51d2496bcbb350a...
I think this is ready to be committed.
Comment #9
mpp CreditAttribution: mpp at AmeXio for District09 commented+1 RTBC
Comment #12
poker10 CreditAttribution: poker10 at ActivIT s.r.o. commentedThanks all!