Skip to content

PHP 8.1 json_decode(null) deprecated when creating new Access Level#39297

Merged
fancyFranci merged 2 commits intojoomla:4.2-devfrom
OctavianC:patch-2
Jan 8, 2023
Merged

PHP 8.1 json_decode(null) deprecated when creating new Access Level#39297
fancyFranci merged 2 commits intojoomla:4.2-devfrom
OctavianC:patch-2

Conversation

@OctavianC
Copy link
Copy Markdown
Contributor

Testing Instructions

  • Switch to PHP 8.1 and set Error Reporting to Maximum
  • Go to Users > Access Levels > click New

Actual result BEFORE applying this Pull Request

Deprecated warning showing up
image

Expected result AFTER applying this Pull Request

No warnings
image

@alikon
Copy link
Copy Markdown
Contributor

alikon commented Nov 24, 2022

see #38467 too

@richard67
Copy link
Copy Markdown
Member

So we have 2 PRs for the same issue, this one and #38467 . While this here changes $result->rules to an empty array when it is null, the other one leaves it as it is and just doesn't try to decode it. I'm not sure what's better, but I tend to think the other PR is better.

@richard67 richard67 added the PHP 8.x PHP 8.x deprecated issues label Nov 24, 2022
@nibra
Copy link
Copy Markdown
Member

nibra commented Nov 26, 2022

Most simple solution:

$result->rules = json_decode($result->rules ?? '{}');

since $result->rules is expected to be an array afterwards.

@HLeithner
Copy link
Copy Markdown
Member

And non of the solutions documents why this value could be empty.

@alikon alikon mentioned this pull request Jan 7, 2023
4 tasks
@joomdonation
Copy link
Copy Markdown
Contributor

I have tested this item ✅ successfully on 4be4e9d


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

@joomdonation
Copy link
Copy Markdown
Contributor

And non of the solutions documents why this value could be empty.

It is null because when we create a new level, getItem() method from AdminModel just return an object of that item with all fields from that table set to null. For reference :

@alikon
Copy link
Copy Markdown
Contributor

alikon commented Jan 8, 2023

I have tested this item ✅ successfully on 4be4e9d


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

@richard67
Copy link
Copy Markdown
Member

RTC


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

@joomla-cms-bot joomla-cms-bot added the RTC This Pull Request is Ready To Commit label Jan 8, 2023
@fancyFranci fancyFranci merged commit 23c43ed into joomla:4.2-dev Jan 8, 2023
@fancyFranci fancyFranci added this to the Joomla! 4.2.7 milestone Jan 8, 2023
@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label Jan 8, 2023
@fancyFranci
Copy link
Copy Markdown
Contributor

Thanks, everybody

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.

8 participants