ezsql icon indicating copy to clipboard operation
ezsql copied to clipboard

Argument #2 ($arg) must be passed by reference, value given

Open Nightmare opened this issue 1 year ago • 3 comments

I'm probably missing something out, but the query is simple and the row is correctly inserted into the db.

I installed it with composer ezsql/ezsql on windows, xampp, php 8.1.4

the, double, error

Warning: ezsql\Database\ez_mysqli::ezsql\Database{closure}(): Argument #2 ($arg) must be passed by reference, value given in C:\xampp\htdocs\vendor\ezsql\ezsql\lib\Database\ez_mysqli.php on line 307

Warning: ezsql\Database\ez_mysqli::ezsql\Database{closure}(): Argument #2 ($arg) must be passed by reference, value given in C:\xampp\htdocs\vendor\ezsql\ezsql\lib\Database\ez_mysqli.php on line 307

use ezsql\Config;
use ezsql\Database\ez_mysqli;

$dsn_path_user	= 'root';
$password	= '';
$database	= 'database';
$other_settings	= '';

$settings = new Config('mysqli', [$dsn_path_user, $password, $database, $other_settings]);

$db = new ez_mysqli($settings);

$db->prepareOn(); // with and without prepareOn

$values = [];
$values['name'] = "test name";
$values['status'] = '1';
$name = 'test name';
$status = 1;
$db->insert('meetings', $values);

i also tried, same error, and new row in the db is inserted.

$db->insert('meetings', ['name' => $name, 'status' => $status]);

or

$db->insert('meetings', ['visitor_name' => "$name", 'status' => "$status"]);

if I do simple query without shortcut it works without errors

$db->query("INSERT INTO meetings (visitor_name, status) VALUES ('$name', 1)");

Thank you

Nightmare avatar Dec 29 '23 17:12 Nightmare

There are various issues with PHP 8+, and haven't gotten around to addressing.

Seems the warnings is expected starting with PHP 8 to show according to https://www.php.net/manual/en/function.array-reduce.php

You can submit PR to address function array_reduce signature/callback or try pass null instead of ''.

TheTechsTech avatar Dec 29 '23 23:12 TheTechsTech

Hi, please compare with this issue: https://github.com/elastic/elasticsearch-php/issues/1085 Same behavior for array-reduce and array_walk : https://www.php.net/manual/en/function.array-reduce.php removing the & in line 294 in lib/Database/ez_mysqli.php solves the problem:

- function ($string, &$arg) use (&$params) {
+ function ($string, $arg) use (&$params) {

wninaus avatar Jan 29 '24 09:01 wninaus

Seems reasonable, have you tried the patch on PHP 7.4 to see for BC?

TheTechsTech avatar Jan 31 '24 17:01 TheTechsTech