j4mie / idiorm

A lightweight nearly-zero-configuration object-relational mapper and fluent query builder for PHP5.
http://j4mie.github.com/idiormandparis/
2.01k stars 369 forks source link

PHP8.1 compatibility issue on logging null #374

Open howan4work opened 1 year ago

howan4work commented 1 year ago

Version: v1.5.8

Output Deprecated: PDO::quote(): Passing null to parameter #1 ($string) of type string is deprecated in C:\VHOST\VHOST8\idiorm\vendor\j4mie\idiorm\idiorm.php on line 539

Testing Code

<?php
declare(strict_types=1);
require_once "vendor/autoload.php";
date_default_timezone_set('Asia/Hong_Kong');
ini_set("assert.exception", "1");
//error_reporting(E_ALL & ~E_DEPRECATED);

/*
CREATE TABLE `testing` (
    `id` INT(11) NOT NULL AUTO_INCREMENT,
    `timestamp` DATETIME NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
    PRIMARY KEY (`id`) USING BTREE
) COLLATE='utf8_general_ci' ENGINE=InnoDB;
*/
try{
    $hFile = fopen(__DIR__.DIRECTORY_SEPARATOR."run.log", 'w');
    $writeLine = function(string $message) use ($hFile):void{
        fwrite($hFile, $message.PHP_EOL);
    };
    $arrConfig = [
        'connection_string'=>'mysql:host=localhost;dbname=temp',
        'username'=>'root',
        'password'=>'P@ssw0rd',
        'return_result_sets'=>TRUE,
        'driver_options'=>[PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'],
        'error_mode'=>PDO::ERRMODE_EXCEPTION,
        'logging' => TRUE,
        'logger' => function($query, $time) use ($writeLine):void{
            $log = sprintf("[SQL %07.3f] %s", $time, $query);
            $writeLine($log);
        },
    ];
    ORM::configure($arrConfig);
    $orm = ORM::forTable("testing")->create();
    if(!$orm->save()) $writeLine("Create Fails");
    $id = intval($orm->id);
    $orm = ORM::forTable("testing")->findOne($id);
    $writeLine("Id# {$id} and get ".($orm->timestamp??"<NULL>"));
    $orm->timestamp = '2022-12-12 12:12:12';
    $orm->save();
    $writeLine("Id# {$id} and get ".($orm->timestamp??"<NULL>"));
    $orm->timestamp = NULL;
    $orm->save();
    $writeLine("Id# {$id} and get ".($orm->timestamp??"<NULL>"));
    if($hFile) fclose($hFile);
} catch (Throwable $ex){
    $writeLine("[Throwable] ".$ex->getMessage());
    if($hFile) fclose($hFile);
}

Beside the notice, the logged SQL is not correct. [SQL 000.007] UPDATEtestingSETtimestamp= '' WHEREid= '8'