Skip to content

A free, self-hostable news aggregator…

Use Pdo\Mysql for PHP 8.5+ (and update PHPStan) (#8526)

Alexandre Alapetite41031fc6d3dc
diff --git a/app/Models/Search.php b/app/Models/Search.php
index b1dae8cc3..30bbb87ca 100644
--- a/app/Models/Search.php
+++ b/app/Models/Search.php
@@ -190,7 +190,7 @@ class FreshRSS_Search implements \Stringable {
foreach ($properties as $property) {
// @phpstan-ignore property.dynamicName, property.dynamicName
if (gettype($this->$property) !== gettype($search->$property)) {
- if (str_contains($property, 'min_') || str_contains($property, 'max_')) {
+ if (is_string($property) && (str_contains($property, 'min_') || str_contains($property, 'max_'))) {
// Process {min_*, max_*} pairs together (for dates)
$mate = str_contains($property, 'min_') ? str_replace('min_', 'max_', $property) : str_replace('max_', 'min_', $property);
// @phpstan-ignore property.dynamicName, property.dynamicName, property.dynamicName, property.dynamicName
@@ -226,7 +226,7 @@ class FreshRSS_Search implements \Stringable {
if ($search->$property !== null) {
// @phpstan-ignore property.dynamicName, property.dynamicName
$result->$property = $search->$property;
- if (str_contains($property, 'min_') || str_contains($property, 'max_')) {
+ if (is_string($property) && (str_contains($property, 'min_') || str_contains($property, 'max_'))) {
// Process {min_*, max_*} pairs together (for dates)
$mate = str_contains($property, 'min_') ? str_replace('min_', 'max_', $property) : str_replace('max_', 'min_', $property);
// @phpstan-ignore property.dynamicName, property.dynamicName
@@ -251,7 +251,7 @@ class FreshRSS_Search implements \Stringable {
if ($search->$property !== null) {
// @phpstan-ignore property.dynamicName
$result->$property = null;
- if (str_contains($property, 'min_') || str_contains($property, 'max_')) {
+ if (is_string($property) && (str_contains($property, 'min_') || str_contains($property, 'max_'))) {
// Process {min_*, max_*} pairs together (for dates)
$mate = str_contains($property, 'min_') ? str_replace('min_', 'max_', $property) : str_replace('max_', 'min_', $property);
// @phpstan-ignore property.dynamicName
diff --git a/composer.lock b/composer.lock
index c4cb7374f..5807dc50f 100644
--- a/composer.lock
+++ b/composer.lock
@@ -245,11 +245,11 @@
},
{
"name": "phpstan/phpstan",
- "version": "2.1.38",
+ "version": "2.1.39",
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/phpstan/phpstan/zipball/dfaf1f530e1663aa167bc3e52197adb221582629",
- "reference": "dfaf1f530e1663aa167bc3e52197adb221582629",
+ "url": "https://api.github.com/repos/phpstan/phpstan/zipball/c6f73a2af4cbcd99c931d0fb8f08548cc0fa8224",
+ "reference": "c6f73a2af4cbcd99c931d0fb8f08548cc0fa8224",
"shasum": ""
},
"require": {
@@ -294,25 +294,25 @@
"type": "github"
}
],
- "time": "2026-01-30T17:12:46+00:00"
+ "time": "2026-02-11T14:48:56+00:00"
},
{
"name": "phpstan/phpstan-deprecation-rules",
- "version": "2.0.3",
+ "version": "2.0.4",
"source": {
"type": "git",
"url": "https://github.com/phpstan/phpstan-deprecation-rules.git",
- "reference": "468e02c9176891cc901143da118f09dc9505fc2f"
+ "reference": "6b5571001a7f04fa0422254c30a0017ec2f2cacc"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/phpstan/phpstan-deprecation-rules/zipball/468e02c9176891cc901143da118f09dc9505fc2f",
- "reference": "468e02c9176891cc901143da118f09dc9505fc2f",
+ "url": "https://api.github.com/repos/phpstan/phpstan-deprecation-rules/zipball/6b5571001a7f04fa0422254c30a0017ec2f2cacc",
+ "reference": "6b5571001a7f04fa0422254c30a0017ec2f2cacc",
"shasum": ""
},
"require": {
"php": "^7.4 || ^8.0",
- "phpstan/phpstan": "^2.1.15"
+ "phpstan/phpstan": "^2.1.39"
},
"require-dev": {
"php-parallel-lint/php-parallel-lint": "^1.2",
@@ -337,24 +337,27 @@
"MIT"
],
"description": "PHPStan rules for detecting usage of deprecated classes, methods, properties, constants and traits.",
+ "keywords": [
+ "static analysis"
+ ],
"support": {
"issues": "https://github.com/phpstan/phpstan-deprecation-rules/issues",
- "source": "https://github.com/phpstan/phpstan-deprecation-rules/tree/2.0.3"
+ "source": "https://github.com/phpstan/phpstan-deprecation-rules/tree/2.0.4"
},
- "time": "2025-05-14T10:56:57+00:00"
+ "time": "2026-02-09T13:21:14+00:00"
},
{
"name": "phpstan/phpstan-phpunit",
- "version": "2.0.12",
+ "version": "2.0.16",
"source": {
"type": "git",
"url": "https://github.com/phpstan/phpstan-phpunit.git",
- "reference": "e4c5a22bf43d3d2bd5a780ad261a622ff62c49a4"
+ "reference": "6ab598e1bc106e6827fd346ae4a12b4a5d634c32"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/phpstan/phpstan-phpunit/zipball/e4c5a22bf43d3d2bd5a780ad261a622ff62c49a4",
- "reference": "e4c5a22bf43d3d2bd5a780ad261a622ff62c49a4",
+ "url": "https://api.github.com/repos/phpstan/phpstan-phpunit/zipball/6ab598e1bc106e6827fd346ae4a12b4a5d634c32",
+ "reference": "6ab598e1bc106e6827fd346ae4a12b4a5d634c32",
"shasum": ""
},
"require": {
@@ -390,29 +393,32 @@
"MIT"
],
"description": "PHPUnit extensions and rules for PHPStan",
+ "keywords": [
+ "static analysis"
+ ],
"support": {
"issues": "https://github.com/phpstan/phpstan-phpunit/issues",
- "source": "https://github.com/phpstan/phpstan-phpunit/tree/2.0.12"
+ "source": "https://github.com/phpstan/phpstan-phpunit/tree/2.0.16"
},
- "time": "2026-01-22T13:40:00+00:00"
+ "time": "2026-02-14T09:05:21+00:00"
},
{
"name": "phpstan/phpstan-strict-rules",
- "version": "2.0.8",
+ "version": "2.0.10",
"source": {
"type": "git",
"url": "https://github.com/phpstan/phpstan-strict-rules.git",
- "reference": "1ed9e626a37f7067b594422411539aa807190573"
+ "reference": "1aba28b697c1e3b6bbec8a1725f8b11b6d3e5a5f"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/phpstan/phpstan-strict-rules/zipball/1ed9e626a37f7067b594422411539aa807190573",
- "reference": "1ed9e626a37f7067b594422411539aa807190573",
+ "url": "https://api.github.com/repos/phpstan/phpstan-strict-rules/zipball/1aba28b697c1e3b6bbec8a1725f8b11b6d3e5a5f",
+ "reference": "1aba28b697c1e3b6bbec8a1725f8b11b6d3e5a5f",
"shasum": ""
},
"require": {
"php": "^7.4 || ^8.0",
- "phpstan/phpstan": "^2.1.29"
+ "phpstan/phpstan": "^2.1.39"
},
"require-dev": {
"php-parallel-lint/php-parallel-lint": "^1.2",
@@ -438,11 +444,14 @@
"MIT"
],
"description": "Extra strict and opinionated rules for PHPStan",
+ "keywords": [
+ "static analysis"
+ ],
"support": {
"issues": "https://github.com/phpstan/phpstan-strict-rules/issues",
- "source": "https://github.com/phpstan/phpstan-strict-rules/tree/2.0.8"
+ "source": "https://github.com/phpstan/phpstan-strict-rules/tree/2.0.10"
},
- "time": "2026-01-27T08:10:25+00:00"
+ "time": "2026-02-11T14:17:32+00:00"
},
{
"name": "phpunit/php-code-coverage",
diff --git a/config.default.php b/config.default.php
index adb64a633..99a039801 100644
--- a/config.default.php
+++ b/config.default.php
@@ -185,9 +185,9 @@ return [
# Additional PDO parameters, such as offered by MySQL https://php.net/ref.pdo-mysql
'pdo_options' => [
- //PDO::MYSQL_ATTR_SSL_KEY => '/path/to/client-key.pem',
- //PDO::MYSQL_ATTR_SSL_CERT => '/path/to/client-cert.pem',
- //PDO::MYSQL_ATTR_SSL_CA => '/path/to/ca-cert.pem',
+ //Pdo\Mysql::ATTR_SSL_KEY => '/path/to/client-key.pem',
+ //Pdo\Mysql::ATTR_SSL_CERT => '/path/to/client-cert.pem',
+ //Pdo\Mysql::ATTR_SSL_CA => '/path/to/ca-cert.pem',
],
],
diff --git a/lib/Minz/ModelPdo.php b/lib/Minz/ModelPdo.php
index e481911bc..e46b7e981 100644
--- a/lib/Minz/ModelPdo.php
+++ b/lib/Minz/ModelPdo.php
@@ -57,8 +57,12 @@ class Minz_ModelPdo {
if (!empty($dbServer['port'])) {
$dsn .= ';port=' . $dbServer['port'];
}
- $driver_options[PDO::MYSQL_ATTR_INIT_COMMAND] = 'SET NAMES utf8mb4';
- $this->pdo = new Minz_PdoMysql($dsn . $dsnParams, $db['user'], $db['password'], $driver_options);
+ if (class_exists('Pdo\Mysql')) {
+ $driver_options[Pdo\Mysql::ATTR_INIT_COMMAND] = 'SET NAMES utf8mb4'; // @phpstan-ignore offsetAccess.invalidOffset
+ } else {
+ $driver_options[PDO::MYSQL_ATTR_INIT_COMMAND] = 'SET NAMES utf8mb4'; // PHP < 8.4
+ }
+ $this->pdo = new Minz_PdoMysql($dsn . $dsnParams, $db['user'], $db['password'], $driver_options); // @phpstan-ignore argument.type
$this->pdo->setPrefix($db['prefix'] . $this->current_user . '_');
break;
case 'sqlite':
diff --git a/lib/Minz/PdoMysql.php b/lib/Minz/PdoMysql.php
index d7fca0168..98156ad0e 100644
--- a/lib/Minz/PdoMysql.php
+++ b/lib/Minz/PdoMysql.php
@@ -13,7 +13,11 @@ class Minz_PdoMysql extends Minz_Pdo {
*/
public function __construct(string $dsn, ?string $username = null, ?string $passwd = null, ?array $options = null) {
parent::__construct($dsn, $username, $passwd, $options);
- $this->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);
+ if (class_exists('Pdo\Mysql')) {
+ $this->setAttribute(Pdo\Mysql::ATTR_USE_BUFFERED_QUERY, false); // @phpstan-ignore argument.type
+ } else {
+ $this->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false); // PHP < 8.4
+ }
}
#[\Override]