Skip to content

[5.2] PHP Deprecated: trim(): Passing null to parameter #1 ($string) of type string is deprecated#44876

Merged
pe7er merged 5 commits intojoomla:5.2-devfrom
alikon:patch-18
Feb 20, 2025
Merged

[5.2] PHP Deprecated: trim(): Passing null to parameter #1 ($string) of type string is deprecated#44876
pe7er merged 5 commits intojoomla:5.2-devfrom
alikon:patch-18

Conversation

@alikon
Copy link
Copy Markdown
Contributor

@alikon alikon commented Feb 13, 2025

Pull Request for Issue ##44872 .

Summary of Changes

fix PHP Deprecated: trim(): Passing null to parameter

Testing Instructions

Set Error Reporting to Maximum.
Edit a banner.
Type in a new category.
Select Save & Close button.
See PHP error log:

Actual result BEFORE applying this Pull Request

Deprecated

Expected result AFTER applying this Pull Request

no more Deprecated

Link to documentations

Please select:

  • Documentation link for docs.joomla.org:

  • No documentation changes for docs.joomla.org needed

  • Pull Request link for manual.joomla.org:

  • No documentation changes for manual.joomla.org needed

@QuyTon
Copy link
Copy Markdown
Contributor

QuyTon commented Feb 15, 2025

I have tested this item ✅ successfully on 0059c80


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

@richard67
Copy link
Copy Markdown
Member

richard67 commented Feb 15, 2025

Hmm, I'm not sure if this PR is right. Currently without the PR, the trim is applied on the alias before the check if it is empty:

$this->alias = trim($this->alias);

if (empty($this->alias)) {
    $this->alias = $this->title;
}

So if someone enters spaces as alias in the form, that will not be used, and the title will be used.

Now with the PR you move trim to after the check, so if someone enters spaces as alias in the form, it will be used and not the title because the empty check for a string with spaces will return false:

if (empty($this->alias)) {
    $this->alias = $this->title;
}

$this->alias = trim($this->alias);

Maybe the following code would be better?

$this->alias = trim($this->alias ?? '');

if (empty($this->alias)) {
    $this->alias = $this->title;
}

I.e. leave order of processing like it is without this PR and use the null coalescing operator inside the trim call to not let it operate on a null value.

@joomdonation
Copy link
Copy Markdown
Contributor

Agree with Richard. @alikon Could you please implement the change suggested by Richard?

@alikon
Copy link
Copy Markdown
Contributor Author

alikon commented Feb 16, 2025

done

@joomdonation
Copy link
Copy Markdown
Contributor

I have tested this item ✅ successfully on 3ac3c7c


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

@QuyTon
Copy link
Copy Markdown
Contributor

QuyTon commented Feb 16, 2025

RTC


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

@joomla-cms-bot joomla-cms-bot added the RTC This Pull Request is Ready To Commit label Feb 16, 2025
@QuyTon QuyTon added the bug label Feb 16, 2025
@pe7er pe7er self-assigned this Feb 20, 2025
@QuyTon QuyTon added this to the Joomla! 5.2.5 milestone Feb 20, 2025
@pe7er pe7er enabled auto-merge (squash) February 20, 2025 18:17
@pe7er pe7er merged commit 64ac8c8 into joomla:5.2-dev Feb 20, 2025
3 checks passed
@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label Feb 20, 2025
@pe7er
Copy link
Copy Markdown
Contributor

pe7er commented Feb 20, 2025

Thanks @alikon !

@alikon alikon deleted the patch-18 branch February 22, 2025 07:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants