Deprecated trim()

Hi I receive a lot of messages like this since I'm running Zenphoto 1.6 on PHP 8.1.13:

DEPRECATED: trim(): Passing null to parameter #1 ($string) of type string is deprecated in zp-core/classes/class-image.php on line 965
trim called from Image->getCopyrightNotice (class-image.php [965])
from htmlmetatags::getHTMLMetaData (html_meta_tags.php [286])
from zp_apply_filter (functions-filter.php [150])
from include (_head.php [116])
from include (image.php [9])
from include (index.php [128])
from index.php [79]

As it is a zp-core function I don't want to change that on my own ;-)


  • acrylian Administrator, Developer

    We traditionally use NULL as the default value for a lot of things traditionally if not set. But some PHP core functions like trim() and others respectively PHP itself are now more type strict in PHP 8.1 and require string parameters to get string values. So instead of null that must be an empty string.

    We have fixed loads of these but for sure didn't catch all (And I was sure we had this one already…)

    In case you or anyone encounters this with custom code: We cannot fix the actual origins of these values - null values are even in the db - without possibly breaking things unwantedly (as we also use is_null() a lot).

    So the pragmatic ix is actually to just use strval() (or intval() as the same applies with expect integers on other functions) when passing to affected functions.

Sign In or Register to comment.