Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

PHP 8.1 / Ad-Hoc field with NULL value #339

Closed
wildtierschweiz opened this issue Mar 23, 2022 · 1 comment
Closed

PHP 8.1 / Ad-Hoc field with NULL value #339

wildtierschweiz opened this issue Mar 23, 2022 · 1 comment
Labels

Comments

@wildtierschweiz
Copy link

wildtierschweiz commented Mar 23, 2022

https://github.com/bcosca/fatfree-core/blob/ee8ad6460ff33514a6b705cc8bff57e2b5048e3b/db/sql.php#L128

fatfree-core 3.8.0 / PHP 8.1 / MySQL-MariaDB

This code uses an Ad-Hoc field "max_sortorder"

<?php
// ad-hoc
$this->max_sortorder = 'MAX(sortorder)';
$this->load(['id_bill = ? AND id_product >= 0 AND is_deleted = 0', $id_bill_]);
$_result = (int)$this->max_sortorder + 1;
return $_result;

The Problem is, when the Ad-Hoc field results in NULL, when no record hydrades the mapper.
The code fails in PHP 8.1, because the str_replace() call somehow gets passed NULL as the third parameter, which is depricated.

str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

I tried this to work around, but did not succeed:

<?php
// ad-hoc
$this->max_sortorder = 'COALESCE(MAX(sortorder), 0)';

My current work around that works is this:

<?php
if (!$this->count(['id_bill = ? AND id_product >= 0 AND is_deleted = 0', $id_bill_]))
    return 0;
// ad-hoc
$this->max_sortorder = 'MAX(sortorder)';
$this->load(['id_bill = ? AND id_product >= 0 AND is_deleted = 0', $id_bill_]);
$_result = (int)$this->max_sortorder + 1;
return $_result;
@ikkez
Copy link
Member

ikkez commented Apr 27, 2022

Hi. I wasn't able to reproduce this. Perhaps a minor version issue or something. However, since bcosca/fatfree#1252 also reported this same behaviour, I tried to patch this part slightly. Can you have a look at the latest commit and see if this solves the issue? thank you.

@ikkez ikkez added the bug label Apr 29, 2022
@ikkez ikkez closed this as completed Apr 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants