Skip to content

Commit c333f97

Browse files
committed
Fix "strtolower(): Passing null to parameter #1 ($string) of type string is deprecated" on PHP >= 8.4
1 parent def2400 commit c333f97

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

tests/WP_SQLite_Driver_Tests.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6276,6 +6276,33 @@ public function testUserVariables(): void {
62766276
$this->assertEquals( 3, $result[0]->{'@my_var'} );
62776277
}
62786278

6279+
public function testVariableBackupAndRestoreForDumps(): void {
6280+
// Set and backup variables.
6281+
$this->assertQuery( '/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;' );
6282+
$this->assertQuery( '/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;' );
6283+
$this->assertQuery( '/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;' );
6284+
$this->assertQuery( '/*!50503 SET NAMES utf8mb4 */;' );
6285+
$this->assertQuery( '/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;' );
6286+
$this->assertQuery( "/*!40103 SET TIME_ZONE='+00:00' */;" );
6287+
$this->assertQuery( '/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;' );
6288+
$this->assertQuery( '/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;' );
6289+
$this->assertQuery( "/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;" );
6290+
$this->assertQuery( '/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;' );
6291+
$this->assertQuery( '/*!40101 SET @saved_cs_client = @@character_set_client */; ' );
6292+
$this->assertQuery( '/*!50503 SET character_set_client = utf8mb4 */;' );
6293+
6294+
// Restore variables.
6295+
$this->assertQuery( '/*!40101 SET character_set_client = @saved_cs_client */;' );
6296+
$this->assertQuery( '/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;' );
6297+
$this->assertQuery( '/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;' );
6298+
$this->assertQuery( '/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;' );
6299+
$this->assertQuery( '/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;' );
6300+
$this->assertQuery( '/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;' );
6301+
$this->assertQuery( '/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;' );
6302+
$this->assertQuery( '/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;' );
6303+
$this->assertQuery( '/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;' );
6304+
}
6305+
62796306
public function testLockingStatements(): void {
62806307
$this->assertQuery( 'CREATE TABLE t (id INT)' );
62816308

wp-includes/sqlite-ast/class-wp-sqlite-driver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2925,7 +2925,7 @@ private function execute_set_system_variable_statement(
29252925
* SET updatable_views_with_limit = OFF; ERROR 1231 (42000)
29262926
* SET updatable_views_with_limit = false; SELECT @@updatable_views_with_limit; -> NO
29272927
*/
2928-
$lowercase_value = strtolower( $value );
2928+
$lowercase_value = null === $value ? null : strtolower( $value );
29292929
if ( 'on' === $lowercase_value || 'off' === $lowercase_value ) {
29302930
$value = 'on' === $lowercase_value ? 1 : 0;
29312931
}

0 commit comments

Comments
 (0)