• Payment Plugins Poll

    We need your feedback on the need for updated payment plugins. Please go here and give us your feedback.

  • Joomla 5.1

    For running J!5.1 you must install Fabrik 4.1
    See also Announcements

  • Subscription and download (Fabrik 4.1 for J!4.2+ and J!5.1) are working now

    See Announcement
    Please post subscription questions and issues here

    We have resolved the issue with the J! updater and this will be fixed in the next release.

  • Update & Changlog URL Fixer

    At the present time the update site URL for Fabrik is incorrect in all installations up to and including 4.1. This will be corrected in 4.2, however, if you wish to update Fabrik via the J! Updater you can download and install this plugin.

    This file is installed just like any other extension through the J! Extension Installation panel. It will not however actually install anything. Its sole purpose is to fix the Update Site and Changlog URL's. Once done it will simply exit.

    As always, we recommend you perform a site backup priot to installation.

Deprecated: htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated

Status
Not open for further replies.

beatty_t

New Member
Hey All!

I had turned on J error reporting to maximum while working on something outside of Fabrik and forgot to "dial it down" before I opened a Fabrik form. I was prompted with the following Depreciated notice regarding passing null to the trim() function in the field and jdate elements. The following addressed the errors for me and I wondered if within one of the next releases, something similar should be included? It doesn't break anything to leave as is.

Here are the full error messages:

Deprecated: htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated in /www/wwwroot/centralparking.ca/plugins/fabrik_element/jDate/jDate.php on line 1084

Deprecated: htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated in /www/wwwroot/centralparking.ca/plugins/fabrik_element/field/field.php on line 191

Within jdate.php (on line 1084), I replaced:

$value = trim($value, "'");
$value = $value == "" ? null : $value;

With:

if (!empty($value)){

$value = trim($value, "'");

} else {

$value = $value == "" ? null : $value;
}

Within field.php (on line 191), I replaced:

$bits['value'] = htmlspecialchars($value, ENT_COMPAT, 'UTF-8', false);

With:

if (!empty($value)){

$bits['value'] = htmlspecialchars($value, ENT_COMPAT, 'UTF-8', false);

}
 
I am not seeing either of these errors on my site, however, I agree these are a problem. Instead of the code you have above, can you change the first one to:
Code:
        $value = $value ?? trim($value, "'");
        $value = $value == "" ? null : $value;
and the second insert the following before the if statement:
Code:
        $value = $value ?? "";
and advise if these solve your problem. These are just cleaner ways to do what you have done.
 
I am not seeing either of these errors on my site, however, I agree these are a problem. Instead of the code you have above, can you change the first one to:
Code:
        $value = $value ?? trim($value, "'");
        $value = $value == "" ? null : $value;
and the second insert the following before the if statement:
Code:
        $value = $value ?? "";
and advise if these solve your problem. These are just cleaner ways to do what you have done.

Thanks achartier! I updated the field and jDate plugin files with your suggestions. I found that your fix for the htmlspecialchars() worked, but I got the same "Depreciated..." message again after applying your suggestion for a fix to the trim() function. Seeing that your htmlspecialchars() fix worked, I used the same thing to fix the trim() issue:
$value = $value ?? "";
$value = trim($value, "'");
$value = $value == "" ? null : $value;

I've also found a similar issue within the element plugin "internalid" (file path: root/plugins/fabrik_elements/internalid/internalid.php). Within this plugin, I get two "Depreciated..." messages.
1. "Deprecated: stripslashes(): Passing null to parameter #1 ($string) of type string is deprecated in /www/wwwroot/centralparking.ca/plugins/fabrik_element/internalid/internalid.php on line 44" -> so I added the same fix (added $value = $value ?? ""; above $value = stripslashes($value);) as I did for the trim()
2. "Deprecated: htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated in /www/wwwroot/centralparking.ca/plugins/fabrik_element/internalid/internalid.php on line 55" -> again, I added the same fix

I should likely add that my forms do allow for empty values in this use case, so if I'm editing a record, it is possible for a field to be empty/null - which is likely why things like trim(), stripslashes() and htmlspecialchars() functions would be passed an empty string for $value and trigger the messages I get when I have Error Reporting set to Maximum.

If you have any concerns with what I've done, certainly let me know.

Your help was much appreciated!

Best Regards,


Travis
 
Last edited:
Status
Not open for further replies.
Back
Top