Skip to content

Conversation

@sonvnn
Copy link
Contributor

@sonvnn sonvnn commented Aug 18, 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

@wilsonge
Copy link
Contributor

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

@zero-24
Copy link
Contributor

zero-24 commented Aug 18, 2022

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

@sonvnn
Copy link
Contributor Author

sonvnn commented Aug 18, 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

@zero-24
Copy link
Contributor

zero-24 commented Aug 18, 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.

@sonvnn
Copy link
Contributor Author

sonvnn commented Aug 18, 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

@zero-24
Copy link
Contributor

zero-24 commented Aug 18, 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.

@richard67
Copy link
Member

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

@laoneo
Copy link
Member

laoneo commented Aug 18, 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.

@sonvnn
Copy link
Contributor Author

sonvnn commented Aug 19, 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,

@laoneo
Copy link
Member

laoneo commented Aug 19, 2022

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

@sonvnn
Copy link
Contributor Author

sonvnn commented Aug 19, 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,

@laoneo
Copy link
Member

laoneo commented Aug 19, 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 = '';
}

@alikon alikon added the PHP 8.x PHP 8.x deprecated issues label Aug 19, 2022
@sonvnn
Copy link
Contributor Author

sonvnn commented Aug 22, 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!

@laoneo
Copy link
Member

laoneo commented Aug 22, 2022

Looks correct now. Thanks!

@laoneo
Copy link
Member

laoneo commented Aug 22, 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.

@sonvnn
Copy link
Contributor Author

sonvnn commented Aug 22, 2022

@laoneo Thank you! I updated test instructions.

Best Regards,
Sonny

@laoneo laoneo self-assigned this Aug 27, 2022
@laoneo laoneo added the Maintainers Checked Used if the PR is conceptional useful label Aug 27, 2022
@alikon
Copy link
Contributor

alikon commented Sep 2, 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.

@jwaisner
Copy link
Member

jwaisner commented Sep 2, 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.

@jwaisner
Copy link
Member

jwaisner commented Sep 2, 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.

@alikon
Copy link
Contributor

alikon commented Sep 3, 2022

no need to retest @jwaisner only branch merge

@alikon
Copy link
Contributor

alikon commented Sep 3, 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.

@alikon
Copy link
Contributor

alikon commented Sep 3, 2022

RTC


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

@joomla-cms-bot joomla-cms-bot added the RTC This Pull Request is Ready To Commit label Sep 3, 2022
@laoneo
Copy link
Member

laoneo commented Sep 3, 2022

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

@laoneo laoneo changed the base branch from 4.2-dev to 4.3-dev September 4, 2022 10:06
@laoneo laoneo changed the 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 Sep 4, 2022
@laoneo
Copy link
Member

laoneo commented Sep 4, 2022

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

@Quy Quy removed the PR-4.2-dev label Sep 4, 2022
@obuisard obuisard added this to the Joomla! 4.3.0 milestone Sep 4, 2022
@obuisard obuisard merged commit a330591 into joomla:4.3-dev Sep 4, 2022
@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label Sep 4, 2022
@obuisard
Copy link
Contributor

obuisard commented Sep 4, 2022

Thank you all for working on this issue!

@sonvnn sonvnn deleted the patch-1 branch September 6, 2022 04:23
HLeithner added a commit to joomla/Manual that referenced this pull request Mar 7, 2023
* Update new-deprecations.md

* Moved to correct version

---------

Co-authored-by: Harald <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Information Required Maintainers Checked Used if the PR is conceptional useful PHP 8.x PHP 8.x deprecated issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants