autoptimize icon indicating copy to clipboard operation
autoptimize copied to clipboard

Deprecation warning in jsmin.php

Open chesio opened this issue 10 months ago • 7 comments

PHP Deprecated: ord(): Passing null to parameter #1 ($character) of type string is deprecated in /var/www/naturfuehrer/wordpress/wp-content/plugins/autoptimize/classes/external/php/jsmin.php on line 390

The reason seems to be that JSMin::get() method despite having @return string signature... https://github.com/futtta/autoptimize/blob/67c3e531ab3c3aeebb62e6ac0fd42665bceadf28/classes/external/php/jsmin.php#L319-L325

...can actually return null as well: https://github.com/futtta/autoptimize/blob/67c3e531ab3c3aeebb62e6ac0fd42665bceadf28/classes/external/php/jsmin.php#L338-L340

EDIT: I was too quick... There is another path that returns null in this method (and triggers the warning above): https://github.com/futtta/autoptimize/blob/67c3e531ab3c3aeebb62e6ac0fd42665bceadf28/classes/external/php/jsmin.php#L329-L337

chesio avatar Apr 05 '24 20:04 chesio

can you confirm this fixes the deprecation warning @chesio ?

futtta avatar Apr 06 '24 11:04 futtta

can you confirm this fixes the deprecation warning @chesio ?

@futtta Unfortunately, it does not. This fix is incomplete, it has been reported in upstream repo as well: https://github.com/mrclay/jsmin-php/issues/16

Would it make sense to update the whole library? It seems Autoptimize bundles version 2.3.2, while upstream has 2.4.3 as most recent: https://github.com/mrclay/jsmin-php/blob/master/CHANGELOG.md

chesio avatar Apr 08 '24 15:04 chesio

made a small tweak to the current version, can you re-test @chesio

some of the changes in 2.4.3 are already in "my" version (which is different from the original 2.3.2), but it might indeed be time to go to the latest JSmin version. :-)

futtta avatar Apr 09 '24 06:04 futtta

@futtta I apologize, I should have been more explicit in my previous comments.

While the patch prevents one possible source of the deprecation message it does not fix the problem I reported, because JSMin::get() can still return null. The deprecation notice I am seeing is triggered here:

https://github.com/futtta/autoptimize/blob/67c3e531ab3c3aeebb62e6ac0fd42665bceadf28/classes/external/php/jsmin.php#L388-L390

On line 388 JSMin::get() returns null, on line 390 this null value is passed to ord().

As far as I can tell, this has been fixed upstream in https://github.com/mrclay/jsmin-php/commit/a688631f0595ef66436060f545cd13f1a04e674a The fix does not prevent null being returned from JSMin::get(), but fixes all code handling the returned value to expect null as well.

chesio avatar Apr 09 '24 09:04 chesio

arghhhh ... no use in trying put band-aids on the old code, I'll have to bite the bullet. more soon :)

futtta avatar Apr 09 '24 16:04 futtta

reopening so we can test ;-)

@chesio had to make some small tweaks, but this is 99% of jsmin.php, can you test to confirm this fixes the issues you were facing?

futtta avatar May 09 '24 19:05 futtta

@futtta Sorry for keeping you waiting so long. I have now tested the beta branch and I don't get the deprecation warnings anymore! 👍

chesio avatar May 17 '24 15:05 chesio