• Hello Fabrik Community

    Fabrik is now in the hands of the development team that brought you Fabrik for Joomla 4. We have recently transitioned the Fabrik site over to a new server and are busy trying to clean it up. We have upgraded the site to Joomla 4 and are running the latest version of Fabrik 4. We have also upgraded the Xenforo forum software to the latest version. Many of the widgets you might have been used to on the forum are no longer operational, many abandoned by the developers. We hope to bring back some of the important ones as we have time.

    Exciting times to be sure.

    The Fabrik 4.0 Official release is now available. In addition, the Fabrik codebase is now available in a public repository. See the notices about these in the announcements section

    We wish to shout out a very big Thank You to all of you who have made donations. They have really helped. But we can always use more...wink..wink..

    Also a big Thank You to those of you who have been assisting others in the forum. This takes a very big burden off of us as we work on bugs, the website and the future of Fabrik.

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.
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top