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;
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

loopy1492 created an issue. See original summary.

cilefen’s picture

What is the error?

djdevin’s picture

Error 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).

loopy1492’s picture

Thanks, @djdevin! I appreciate it. I actually got it fixed and forgot to take note of the error text. Haha.

mb_lewis’s picture

Status: Needs review » Reviewed & tested by the community

Patch applied cleanly and resolved the issue, moving to RTBC.

poker10’s picture

Added this to a list of PHP 8 issues.

HitchShock’s picture

+1 RTBC, it works on customer sites as well

mcdruid’s picture

Issue tags: +RTBM

Thanks, looks like a straight backport of https://git.drupalcode.org/project/drupal/-/commit/fc7d4a51d2496bcbb350a...

I think this is ready to be committed.

mpp’s picture

+1 RTBC

  • poker10 committed f83b936 on 7.x
    Issue #3273723 by djdevin, loopy1492, swim: fopen() error in...

poker10 credited swim.

poker10’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: -RTBM

Thanks all!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.