From 3e036033592dfb106a099ce0f39216fc48aa0b83 Mon Sep 17 00:00:00 2001
From: catch <6915-catch@users.noreply.drupalcode.org>
Date: Fri, 29 Nov 2024 09:19:22 +0000
Subject: [PATCH] Issue #3465827 by andypost, kim.pepper, arunkumark, catch,
 berdir, quietone: Stop passing E_USER_ERROR to trigger_error() on PHP 8.4

---
 core/lib/Drupal/Component/Diff/Diff.php                | 10 +++++-----
 core/lib/Drupal/Component/Diff/DiffFormatter.php       |  2 +-
 core/lib/Drupal/Component/Diff/Engine/DiffOp.php       |  2 +-
 core/lib/Drupal/Component/Utility/ToStringTrait.php    |  2 +-
 core/lib/Drupal/Core/Database/Query/Condition.php      |  2 +-
 core/modules/big_pipe/src/Render/BigPipe.php           |  6 +++---
 .../big_pipe/tests/src/Functional/BigPipeTest.php      |  4 ++--
 .../Core/StringTranslation/TranslatableMarkupTest.php  |  2 +-
 8 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/core/lib/Drupal/Component/Diff/Diff.php b/core/lib/Drupal/Component/Diff/Diff.php
index 1b5c40a70514..c32be854912b 100644
--- a/core/lib/Drupal/Component/Diff/Diff.php
+++ b/core/lib/Drupal/Component/Diff/Diff.php
@@ -168,24 +168,24 @@ public function closing() {
   public function check($from_lines, $to_lines) {
     @trigger_error(__METHOD__ . '() is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. There is no replacement. See https://www.drupal.org/node/3337942', E_USER_DEPRECATED);
     if (serialize($from_lines) != serialize($this->orig())) {
-      trigger_error("Reconstructed original doesn't match", E_USER_ERROR);
+      trigger_error("Reconstructed original doesn't match", E_USER_WARNING);
     }
     if (serialize($to_lines) != serialize($this->closing())) {
-      trigger_error("Reconstructed closing doesn't match", E_USER_ERROR);
+      trigger_error("Reconstructed closing doesn't match", E_USER_WARNING);
     }
 
     $rev = $this->reverse();
     if (serialize($to_lines) != serialize($rev->orig())) {
-      trigger_error("Reversed original doesn't match", E_USER_ERROR);
+      trigger_error("Reversed original doesn't match", E_USER_WARNING);
     }
     if (serialize($from_lines) != serialize($rev->closing())) {
-      trigger_error("Reversed closing doesn't match", E_USER_ERROR);
+      trigger_error("Reversed closing doesn't match", E_USER_WARNING);
     }
 
     $prevtype = 'none';
     foreach ($this->edits as $edit) {
       if ( $prevtype == $edit->type ) {
-        trigger_error("Edit sequence is non-optimal", E_USER_ERROR);
+        trigger_error("Edit sequence is non-optimal", E_USER_WARNING);
       }
       $prevtype = $edit->type;
     }
diff --git a/core/lib/Drupal/Component/Diff/DiffFormatter.php b/core/lib/Drupal/Component/Diff/DiffFormatter.php
index d70f3e61ad35..87578b385264 100644
--- a/core/lib/Drupal/Component/Diff/DiffFormatter.php
+++ b/core/lib/Drupal/Component/Diff/DiffFormatter.php
@@ -134,7 +134,7 @@ protected function _block($xbeg, $xlen, $ybeg, $ylen, &$edits) {
         $this->_changed($edit->orig, $edit->closing);
       }
       else {
-        trigger_error('Unknown edit type', E_USER_ERROR);
+        trigger_error('Unknown edit type', E_USER_WARNING);
       }
     }
     $this->_end_block();
diff --git a/core/lib/Drupal/Component/Diff/Engine/DiffOp.php b/core/lib/Drupal/Component/Diff/Engine/DiffOp.php
index 735669dc147c..64d1e7b952ae 100644
--- a/core/lib/Drupal/Component/Diff/Engine/DiffOp.php
+++ b/core/lib/Drupal/Component/Diff/Engine/DiffOp.php
@@ -20,7 +20,7 @@ class DiffOp {
    */
   public function reverse() {
     @trigger_error(__METHOD__ . '() is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. There is no replacement. See https://www.drupal.org/node/3337942', E_USER_DEPRECATED);
-    trigger_error('pure virtual', E_USER_ERROR);
+    trigger_error('pure virtual', E_USER_WARNING);
   }
 
   /**
diff --git a/core/lib/Drupal/Component/Utility/ToStringTrait.php b/core/lib/Drupal/Component/Utility/ToStringTrait.php
index 2a77c7b53dfa..6829954f4ebf 100644
--- a/core/lib/Drupal/Component/Utility/ToStringTrait.php
+++ b/core/lib/Drupal/Component/Utility/ToStringTrait.php
@@ -17,7 +17,7 @@ public function __toString() {
     catch (\Exception $e) {
       // User errors in __toString() methods are considered fatal in the Drupal
       // error handler.
-      trigger_error(get_class($e) . ' thrown while calling __toString on a ' . static::class . ' object in ' . $e->getFile() . ' on line ' . $e->getLine() . ': ' . $e->getMessage(), E_USER_ERROR);
+      trigger_error(get_class($e) . ' thrown while calling __toString on a ' . static::class . ' object in ' . $e->getFile() . ' on line ' . $e->getLine() . ': ' . $e->getMessage(), E_USER_WARNING);
       // In case we are using another error handler that did not fatal on the
       // E_USER_ERROR, we terminate execution. However, for test purposes allow
       // a return value.
diff --git a/core/lib/Drupal/Core/Database/Query/Condition.php b/core/lib/Drupal/Core/Database/Query/Condition.php
index 8f48910ebc22..b2ca13acd734 100644
--- a/core/lib/Drupal/Core/Database/Query/Condition.php
+++ b/core/lib/Drupal/Core/Database/Query/Condition.php
@@ -265,7 +265,7 @@ public function compile(Connection $connection, PlaceholderInterface $queryPlace
             // your site is broken.
             // On top of that the database API relies on __toString() which
             // does not allow to throw exceptions.
-            trigger_error('Invalid characters in query operator: ' . $condition['operator'], E_USER_ERROR);
+            trigger_error('Invalid characters in query operator: ' . $condition['operator'], E_USER_WARNING);
             return;
           }
 
diff --git a/core/modules/big_pipe/src/Render/BigPipe.php b/core/modules/big_pipe/src/Render/BigPipe.php
index 1f2ae1807c06..8f0144c6280f 100644
--- a/core/modules/big_pipe/src/Render/BigPipe.php
+++ b/core/modules/big_pipe/src/Render/BigPipe.php
@@ -416,7 +416,7 @@ protected function sendNoJsPlaceholders($html, $no_js_placeholders, AttachedAsse
           throw $e;
         }
         else {
-          trigger_error($e, E_USER_ERROR);
+          trigger_error($e, E_USER_WARNING);
           continue;
         }
       }
@@ -452,7 +452,7 @@ protected function sendNoJsPlaceholders($html, $no_js_placeholders, AttachedAsse
           throw $e;
         }
         else {
-          trigger_error($e, E_USER_ERROR);
+          trigger_error($e, E_USER_WARNING);
           continue;
         }
       }
@@ -603,7 +603,7 @@ protected function sendPlaceholders(array $placeholders, array $placeholder_orde
             throw $e;
           }
           else {
-            trigger_error($e, E_USER_ERROR);
+            trigger_error($e, E_USER_WARNING);
           }
         }
       }
diff --git a/core/modules/big_pipe/tests/src/Functional/BigPipeTest.php b/core/modules/big_pipe/tests/src/Functional/BigPipeTest.php
index c319835d2477..0cf2631531c7 100644
--- a/core/modules/big_pipe/tests/src/Functional/BigPipeTest.php
+++ b/core/modules/big_pipe/tests/src/Functional/BigPipeTest.php
@@ -195,9 +195,9 @@ public function testBigPipe(): void {
     // database drivers the ability to insert their own limit and offset
     // functionality.
     $records = $connection->select('watchdog', 'w')->fields('w')->orderBy('wid', 'DESC')->range(0, 2)->execute()->fetchAll();
-    $this->assertEquals(RfcLogLevel::ERROR, $records[0]->severity);
+    $this->assertEquals(RfcLogLevel::WARNING, $records[0]->severity);
     $this->assertStringContainsString('Oh noes!', (string) unserialize($records[0]->variables)['@message']);
-    $this->assertEquals(RfcLogLevel::ERROR, $records[1]->severity);
+    $this->assertEquals(RfcLogLevel::WARNING, $records[1]->severity);
     $this->assertStringContainsString('You are not allowed to say llamas are not cool!', (string) unserialize($records[1]->variables)['@message']);
 
     // Verify that 4xx responses work fine. (4xx responses are handled by
diff --git a/core/tests/Drupal/Tests/Core/StringTranslation/TranslatableMarkupTest.php b/core/tests/Drupal/Tests/Core/StringTranslation/TranslatableMarkupTest.php
index dad1cbe102fa..899e22e288fb 100644
--- a/core/tests/Drupal/Tests/Core/StringTranslation/TranslatableMarkupTest.php
+++ b/core/tests/Drupal/Tests/Core/StringTranslation/TranslatableMarkupTest.php
@@ -79,7 +79,7 @@ public function testToString(): void {
     (string) $text;
     restore_error_handler();
 
-    $this->assertEquals(E_USER_ERROR, $this->lastErrorNumber);
+    $this->assertEquals(E_USER_WARNING, $this->lastErrorNumber);
     $this->assertMatchesRegularExpression('/Exception thrown while calling __toString on a .*Mock_TranslatableMarkup_.* object in .*TranslatableMarkupTest.php on line [0-9]+: Yes you may./', $this->lastErrorMessage);
   }
 
-- 
GitLab