Skip to content

Conversation

@beat
Copy link
Contributor

@beat beat commented Jan 23, 2022

Pull Request for Issue # none

Summary of Changes

Fixes MVC BaseController for warnings:

Deprecated: ucfirst(): Passing null to parameter #1 ($string) of type string is deprecated in /home/beat/www/j/libraries/src/MVC/Controller/BaseController.php on line 286
and
Deprecated: strtolower(): Passing null to parameter #1 ($string) of type string is deprecated in /home/beat/www/j/libraries/src/MVC/Controller/BaseController.php on line 684

Testing Instructions

Code review is probably enough, as trivial.

Check frontend with PHP 8.1 with all errors on and Joomla Debug ON.

Actual result BEFORE applying this Pull Request

Deprecated: ucfirst(): Passing null to parameter #1 ($string) of type string is deprecated in /home/beat/www/j/libraries/src/MVC/Controller/BaseController.php on line 286
Deprecated: strtolower(): Passing null to parameter #1 ($string) of type string is deprecated in /home/beat/www/j/libraries/src/MVC/Controller/BaseController.php on line 684

Expected result AFTER applying this Pull Request

Those warnings disappeared.

Documentation Changes Required

None.

Fixes `Deprecated: ucfirst(): Passing null to parameter #1 ($string) of type string is deprecated in /home/beat/www/j/libraries/src/MVC/Controller/BaseController.php on line 286`
and fixes `Deprecated: strtolower(): Passing null to parameter #1 ($string) of type string is deprecated in /home/beat/www/j/libraries/src/MVC/Controller/BaseController.php on line 684`
@alikon alikon added the PHP 8.x PHP 8.x deprecated issues label Jan 23, 2022
@alikon
Copy link
Contributor

alikon commented Jan 23, 2022

I have tested this item ✅ successfully on d9c64d8


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

Copy link
Contributor

@zero-24 zero-24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm i understand what you did here but wouldnt it be more correct to do something like I have done with the suggestions? Else $task != $this->task which does not sound right to me.

We could also question whether we should accept non strings here in the first place.

*/
public function execute($task)
{
$this->task = $task;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$this->task = $task;
$this->task = (string) $task;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea how the other parts of the code would react with $this->task becoming a string '' instead of null. This is why I have suggested this fix with zero bug risks (keeping in mind this is for 3.10 and in 18 months, it's EOL).

getTask() is called from 26 different places in Joomla, and probably from many third-party developers as well. Having it suddenly return a string '' instead of null in a maintenance release seems as a not so great idea.

I'm not inclined to accept this change-suggestion, for the sake of avoiding potential breaks..

$this->task = $task;

$task = strtolower($task);
$task = strtolower((string) $task);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$task = strtolower((string) $task);
$task = strtolower($this->task);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above:

I have no idea how the other parts of the code would react with $this->task becoming a string '' instead of null. This is why I have suggested this fix with zero bug risks (keeping in mind this is for 3.10 and in 18 months, it's EOL).

getTask() is called from 26 different places in Joomla, and probably from many third-party developers as well. Having it suddenly return a string '' instead of null in a maintenance release seems as a not so great idea.

I'm not inclined to accept this change-suggestion, for the sake of avoiding potential breaks..

@zero-24 zero-24 added this to the Joomla 3.10.6 milestone Jan 23, 2022
@zero-24
Copy link
Contributor

zero-24 commented Jan 23, 2022

Merging. Thanks.

@zero-24 zero-24 merged commit 3de1ce1 into joomla:3.10-dev Jan 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PHP 8.x PHP 8.x deprecated issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants