? Information Required PHP 8.x Maintainers Checked PR-4.3-dev Pending

User tests: Successful: Unsuccessful:

avatar sonvnn
sonvnn
18 Aug 2022

Pull Request for Issue #38510 .

Summary of Changes

If $path is null, it will get '' value instead of run trim() function.

Testing Instructions

  1. Open templates/cassiopeia/index.php
  2. Add code below at the line 17:
use Joomla\CMS\Filesystem\Path;
echo Path::clean(null);
  1. Switch template to cassiopeia, go to front-end and check it.

Actual result BEFORE applying this Pull Request

Deprecated: trim(): Passing null to parameter #1 ($string) of type string is deprecated in /{root}/libraries/src/Filesystem/Path.php on line 198

Expected result AFTER applying this Pull Request

Warning disappear

Documentation Changes Required

No

avatar sonvnn sonvnn - open - 18 Aug 2022
avatar sonvnn sonvnn - change - 18 Aug 2022
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 18 Aug 2022
Category Libraries
avatar wilsonge
wilsonge - comment - 18 Aug 2022

Think we need some more info here because the is_string call immediately above this line should fail before you've reached the trim

avatar zero-24
zero-24 - comment - 18 Aug 2022

I agree I would say we should not pass an empty string to that method in the first place.

avatar sonvnn
sonvnn - comment - 18 Aug 2022

Think we need some more info here because the is_string call immediately above this line should fail before you've reached the trim

@wilsonge @zero-24

If $path = NULL it will pass if (!\is_string($path) && !empty($path)) {

I test in my local with var_dump
var_dump($path, is_string($path), empty($path));

Screen Shot 2022-08-18 at 15 55 47

Result Below

Screen Shot 2022-08-18 at 15 54 42

avatar zero-24
zero-24 - comment - 18 Aug 2022

Yes thats the reason I would not like to add that if else catch in every method that is handeling strings and hide the issues of passing null or empty strings to methods which should not be called with empty strings in the first place.

avatar sonvnn sonvnn - change - 18 Aug 2022
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - change - 18 Aug 2022
Category Libraries Layout Libraries
avatar sonvnn
sonvnn - comment - 18 Aug 2022

Yes thats the reason I would not like to add that if else catch in every method that is handeling strings and hide the issues of passing null or empty strings to methods which should not be called with empty strings in the first place.

Yeah! I fixed it in my component. Anyway, I think other extensions will face that when customer update PHP to 8.1

avatar zero-24
zero-24 - comment - 18 Aug 2022

yes when the extension is ready for 8.1 that message does not come up right? When it is not ready for 8.1 yet the issue should be reported to the developer so it can be fixed right? Right now its not an fatal error by php yet anyway so "hiding" error messages "hides" the issue in the same way but allows the developer to find and fix it too.

avatar richard67
richard67 - comment - 18 Aug 2022

Maybe the
if (!\is_string($path) && !empty($path)) {
should be changed to something like
if ($path === null || (!\is_string($path) && !empty($path))) {
?

avatar laoneo
laoneo - comment - 18 Aug 2022

As long as a library accepts null values is should work properly and not throw different errors on different PHP versions. So making a change in the library is fine.

avatar joomla-cms-bot joomla-cms-bot - change - 19 Aug 2022
Category Libraries Layout Libraries
avatar sonvnn sonvnn - change - 19 Aug 2022
The description was changed
avatar sonvnn sonvnn - edited - 19 Aug 2022
avatar sonvnn
sonvnn - comment - 19 Aug 2022

Maybe the if (!\is_string($path) && !empty($path)) { should be changed to something like if ($path === null || (!\is_string($path) && !empty($path))) { ?

You are right! I updated code with if ($path === null || (!\is_string($path) && !empty($path))) {

Best Regards,

avatar laoneo
laoneo - comment - 19 Aug 2022

This is now a BC break as an exception is thrown when the path is null, which wasn't before.

avatar sonvnn
sonvnn - comment - 19 Aug 2022

This is now a BC break as an exception is thrown when the path is null, which wasn't before.

May you me give a suggestion? Raise an exception to force developer fix in their code or set $path = '' to ignore it. I'm wondering about that.

Thanks & Best Regards,

avatar laoneo
laoneo - comment - 19 Aug 2022

I would go with something like:

if ($path === null) {
	@trigger_error(
		sprintf(
			'Path can not be null, in 5.0 it will throw an exception',
			__METHOD__
		),
		E_USER_DEPRECATED
	);
	$path = '';
}
avatar sonvnn sonvnn - change - 22 Aug 2022
Labels Added: PHP 8.x
avatar sonvnn
sonvnn - comment - 22 Aug 2022

@laoneo Thank you for the suggestion! Because no one came up with a better idea. I have updated the code as per your suggestion.

Please help me check it again!

avatar laoneo
laoneo - comment - 22 Aug 2022

Looks correct now. Thanks!

avatar laoneo
laoneo - comment - 22 Aug 2022

When you update the test instructions and expected/actual result the way, that the testers know what to do, then it is very likely that you change gets merged. You can put something like in testing instructions with some files in core:

  • Add this code to the file XY at line ZZ
  • Open the page XY

Similar to what I did in #38535.

avatar sonvnn sonvnn - edited - 22 Aug 2022
avatar sonvnn sonvnn - change - 22 Aug 2022
The description was changed
avatar sonvnn sonvnn - change - 22 Aug 2022
The description was changed
avatar sonvnn sonvnn - edited - 22 Aug 2022
avatar sonvnn
sonvnn - comment - 22 Aug 2022

@laoneo Thank you! I updated test instructions.

Best Regards,
Sonny

avatar alikon
alikon - comment - 2 Sep 2022

I have tested this item successfully on 3ae8337


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/38511.

avatar alikon alikon - test_item - 2 Sep 2022 - Tested successfully
avatar laoneo laoneo - change - 2 Sep 2022
Labels Added: Maintainers Checked
avatar jwaisner
jwaisner - comment - 2 Sep 2022

I have tested this item successfully on 7e61399


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/38511.

avatar jwaisner jwaisner - test_item - 2 Sep 2022 - Tested successfully
avatar jwaisner
jwaisner - comment - 2 Sep 2022

@alikon , can you please retest since a change was made?


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/38511.

avatar alikon
alikon - comment - 3 Sep 2022

no need to retest @jwaisner only branch merge

avatar alikon
alikon - comment - 3 Sep 2022

I have tested this item successfully on daaf175


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/38511.

avatar alikon alikon - test_item - 3 Sep 2022 - Tested successfully
avatar alikon alikon - change - 3 Sep 2022
Status Pending Ready to Commit
avatar alikon
alikon - comment - 3 Sep 2022

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/38511.

avatar alikon alikon - alter_testresult - 3 Sep 2022 - jwaisner: Tested successfully
avatar laoneo
laoneo - comment - 3 Sep 2022

This has to go into 4.3 as it adds a deprecation. So waiting for the upmerge to make a rebase.

avatar laoneo laoneo - change - 4 Sep 2022
Title
[4.2] Fix issue Deprecated: trim(): Passing null on PHP 8.1
[4.3] Fix issue Deprecated: trim(): Passing null on PHP 8.1
avatar laoneo laoneo - edited - 4 Sep 2022
avatar laoneo laoneo - change - 4 Sep 2022
Labels Added: ? PR-4.3-dev
avatar laoneo
laoneo - comment - 4 Sep 2022

PR for manual can be found here joomla/Manual#33.

avatar laoneo laoneo - change - 4 Sep 2022
Labels Added: Information Required
avatar obuisard obuisard - change - 4 Sep 2022
Status Ready to Commit Fixed in Code Base
Closed_Date 0000-00-00 00:00:00 2022-09-04 14:59:27
Closed_By obuisard
Labels Removed: ?
avatar obuisard obuisard - close - 4 Sep 2022
avatar obuisard obuisard - merge - 4 Sep 2022
avatar obuisard
obuisard - comment - 4 Sep 2022

Thank you all for working on this issue!

Add a Comment

Login with GitHub to post a comment