Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

Open
Nightmare opened this issue Dec 29, 2023 · 3 comments
Open

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

Nightmare opened this issue Dec 29, 2023 · 3 comments
Labels
error-bug Issues causing application termination. warning-bug Issues not causing scripts/routines to die/fail.

Comments

@Nightmare
Copy link

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 Nightmare added error-bug Issues causing application termination. warning-bug Issues not causing scripts/routines to die/fail. labels Dec 29, 2023
@TheTechsTech
Copy link
Contributor

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 ''.

@wninaus
Copy link
Contributor

wninaus commented Jan 29, 2024

Hi,
please compare with this issue: elastic/elasticsearch-php#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) {

@TheTechsTech
Copy link
Contributor

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

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
error-bug Issues causing application termination. warning-bug Issues not causing scripts/routines to die/fail.
Projects
None yet
Development

No branches or pull requests

3 participants