Fix PHP 8.1 compatibility in DatabaseObject::getDatabaseTableIndexName()
authorTim Düsterhus <duesterhus@woltlab.com>
Fri, 13 Aug 2021 08:45:58 +0000 (10:45 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Fri, 13 Aug 2021 08:45:58 +0000 (10:45 +0200)
wcfsetup/install/files/lib/data/DatabaseObject.class.php

index 3c0aae5ddf327f043856ed32bb38fee469098c24..602a635eb5089f7d24f05650ecf83c2af76d5871 100644 (file)
@@ -203,19 +203,20 @@ abstract class DatabaseObject implements IIDObject, IStorableObject
             return static::$databaseTableIndexName;
         }
 
-        static $databaseTableIndexName = null;
-        if ($databaseTableIndexName === null) {
-            $className = \explode('\\', \get_called_class());
+        $className = \get_called_class();
+        static $databaseTableIndexNames = [];
+        if (!isset($databaseTableIndexNames[$className])) {
+            $classParts = \explode('\\', $className);
             $parts = \preg_split(
                 '~(?=[A-Z](?=[a-z]))~',
-                \array_pop($className),
+                \array_pop($classParts),
                 -1,
                 \PREG_SPLIT_DELIM_CAPTURE | \PREG_SPLIT_NO_EMPTY
             );
-            $databaseTableIndexName = \strtolower(\array_pop($parts)) . 'ID';
+            $databaseTableIndexNames[$className] = \strtolower(\array_pop($parts)) . 'ID';
         }
 
-        return $databaseTableIndexName;
+        return $databaseTableIndexNames[$className];
     }
 
     /**