Deprecated - str_replace() - Passing null to parameter #3 ($subject)
Deprecated - str_replace() - Passing null to parameter #3 ($subject)
Hello Allan and Community
I would like to report another PHP deprecated warning related to null being passed on to a function.
We have installed DataTables version 2.3.4 and Editor version 2.5.0. PHP is currently set to version 8.1 but it is intended to upgrade it to a higher version.
The tables were programmed quite a while ago and did not have this issue while they were running on PHP 7. But we have done a server upgrade, with up-to-date Linux, and running PHP 7 is no option anymore; PHP 8 must now be used.
This is the PHP deprecated warning that occurs:
Deprecated: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /var/www/vhosts/.../lib_2.5.0/Editor/Format.php on line 261
This is the function where it occurs:
public static function toDecimalChar($char = ',') {
return static function ($val, $data) use ($char) {
return str_replace('.', $char, $val);
};
}
It is a major undertaking to go through all the tables and make adjustment for this problem in the tables themselves.
As a quick fix I decided to edit the affected section in the Format.php file itself. Here is a possible workaround for this problem:
public static function toDecimalChar($char = ',') {
return static function ($val, $data) use ($char) {
if (isset($val) && $val != null)
return str_replace('.', $char, $val);
else
return null;
};
}
I hope this posting will be helpful to fix these small issues and make this great software more compatible with future PHP versions.
Sincerely,
Gevorg
Replies
Hi Gevorg,
Many thanks for your message. Can you show me the setup for how the Field is configured here please? Are you using
ifEmpty(null)and a formatter, or something else?Allan
Hello Allan.
Always prompt with your replies, I don't know how you do this, maybe you work as a group :-)
Anyway...
It has been a while since I worked on these files, but I will try to answer your question.
Indeed what you mention is being used. Here is one example of how these tables were programmed many years ago:
At the end you have the
which you mention.
Is this way of setting up the fields no longer recommended with the current versions of DataTables / Editor ?
Hi,
Yes, that looks like a spot on way of doing it. I've committed a fix to address this problem and it will be in the next release of Editor. I'll look at getting that out fairly soon - perhaps next week if not tomorrow as there are a couple of little things that need to get pushed out
.
Allan
p.s. Wish I was always this quick!
Thank you.