[TikiWiki-commits] [Git][tikiwiki/tiki][master] [FIX] PHP 8.5: Avoid deprecated PDO/array-offset constructs that corrupt downloaded files

"ushindi bienvenu \(@usbbush\) via TikiWiki-cvs" <[email protected]>
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <6a7cf2951d742_3819f730427e5@gitlab-sidekiq-low-urgency-cpu-bound-v2-6bd4c78bd9-qp2km.mail>

ushindi bienvenu pushed to branch master at Tiki Wiki CMS Groupware / Tiki


Commits:
0f37b882 by Moïse Nturubika at 2026-08-12T22:06:56+00:00
[FIX] PHP 8.5: Avoid deprecated PDO/array-offset constructs that corrupt downloaded files
---
* [FIX] PHP 8.5: Avoid deprecated PDO/array-offset constructs that corrupt downloaded files

See merge request tikiwiki/tiki!10866

- - - - -


2 changed files:

- lib/core/Sections.php
- lib/core/TikiDb/Initializer/Pdo.php


Changes:

=====================================
lib/core/Sections.php
=====================================
@@ -341,7 +341,8 @@ class Sections
     public static function currentObject($request = null)
     {
         global $cat_type, $cat_objid, $postId, $prefs;
-        $section = self::getCurrentSection();
+        // PHP 8.5 deprecates null as an array offset; normalize to ''.
+        $section = self::getCurrentSection() ?? '';
 
         if (! is_array($request)) {
             $request = $_REQUEST; // use the global request object


=====================================
lib/core/TikiDb/Initializer/Pdo.php
=====================================
@@ -14,6 +14,25 @@ class TikiDb_Initializer_Pdo
         return extension_loaded("pdo") && in_array('mysql', PDO::getAvailableDrivers());
     }
 
+    /**
+     * Prefers Pdo\Mysql::* (PHP 8.4+) over the deprecated PDO::MYSQL_* constants.
+     *
+     * @param string $name Constant name without the MYSQL_ prefix, e.g. "ATTR_INIT_COMMAND"
+     * @return int|null
+     */
+    private function mysqlAttrConstant(string $name)
+    {
+        if (class_exists('Pdo\\Mysql') && defined('Pdo\\Mysql::' . $name)) {
+            return constant('Pdo\\Mysql::' . $name);
+        }
+
+        if (defined('PDO::MYSQL_' . $name)) {
+            return constant('PDO::MYSQL_' . $name);
+        }
+
+        return null;
+    }
+
     public function getConnection(array $credentials)
     {
         // Set the host string for PDO dsn.
@@ -33,9 +52,10 @@ class TikiDb_Initializer_Pdo
 
         if ($credentials['charset']) {
             $charset_query = "SET NAMES {$credentials['charset']}";
+            $initCommandAttr = $this->mysqlAttrConstant('ATTR_INIT_COMMAND');
 
-            if (defined('PDO::MYSQL_ATTR_INIT_COMMAND')) {
-                $pdo_options[PDO::MYSQL_ATTR_INIT_COMMAND] = $charset_query;
+            if ($initCommandAttr !== null) {
+                $pdo_options[$initCommandAttr] = $charset_query;
             } else {
                 $pdo_post_queries[] = $charset_query;
             }
@@ -104,13 +124,13 @@ class TikiDb_Initializer_Pdo
 
             if ($isSSL_verify_ca) {
                 // Using 1 .pem file (CA) ie --ssl-mode=VERIFY_CA
-                $pdo_options[PDO::MYSQL_ATTR_SSL_CA] = $fileroot . $caCert;
-                $pdo_options[PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT] = false;
+                $pdo_options[$this->mysqlAttrConstant('ATTR_SSL_CA')] = $fileroot . $caCert;
+                $pdo_options[$this->mysqlAttrConstant('ATTR_SSL_VERIFY_SERVER_CERT')] = false;
             } elseif ($isSSL_verify_identity) {
                 // Using 3 .pem files (CA, Client cert and Client Key) ie --ssl-mode=VERIFY_IDENTITY
-                $pdo_options[PDO::MYSQL_ATTR_SSL_KEY] = $fileroot . $clientKey;
-                $pdo_options[PDO::MYSQL_ATTR_SSL_CERT] = $fileroot . $clientCert;
-                $pdo_options[PDO::MYSQL_ATTR_SSL_CA] = $fileroot . $caCert;
+                $pdo_options[$this->mysqlAttrConstant('ATTR_SSL_KEY')] = $fileroot . $clientKey;
+                $pdo_options[$this->mysqlAttrConstant('ATTR_SSL_CERT')] = $fileroot . $clientCert;
+                $pdo_options[$this->mysqlAttrConstant('ATTR_SSL_CA')] = $fileroot . $caCert;
             }
         }
     }



View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/0f37b8828086aecf3fccd12153be3c67021514fa

-- 
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/0f37b8828086aecf3fccd12153be3c67021514fa
You're receiving this email because of your account on gitlab.com. Manage all notifications: https://gitlab.com/-/profile/notifications | Help: https://gitlab.com/help

_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.