Skip to content

Fix for TypeError: count() in webservices when running PHP 8.x #40610

Merged
obuisard merged 8 commits intojoomla:4.3-devfrom
MacJoom:WebservicesGroupIssue
Jul 20, 2023
Merged

Fix for TypeError: count() in webservices when running PHP 8.x #40610
obuisard merged 8 commits intojoomla:4.3-devfrom
MacJoom:WebservicesGroupIssue

Conversation

@MacJoom
Copy link
Contributor

@MacJoom MacJoom commented May 16, 2023

The error occurs when doing webservices API POST call to /fields/groups/contacts/contact or /fields/groups/content/articles

Pull Request for Issue # .

Summary of Changes

Is_array test before doing count() - not needed FieldsHelper::extract returns null if there are not two parts

Testing Instructions

Code review -

or do test the webservices test with Postman and the collection from here:
https://github.com/alexandreelise/j4x-api-collection

Actual result BEFORE applying this Pull Request

TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given in /var/www/clients/client2/web3/web/joomla-cms/administrator/components/com_fields/src/Model/GroupModel.php:247 etc.

Expected result AFTER applying this Pull Request

No Error, Item is added

Link to documentations

Please select:

  • Documentation link for docs.joomla.org:

  • [x ] No documentation changes for docs.joomla.org needed

  • Pull Request link for manual.joomla.org:

  • [x ] No documentation changes for manual.joomla.org needed

Occurs when using webservices API calls involving groups
@MacJoom MacJoom changed the title Fix for TypeError: count() when running PHP 8.x Fix for TypeError: count() in webservices when running PHP 8.x May 16, 2023
Copy link
Contributor

@wilsonge wilsonge left a comment

Choose a reason for hiding this comment

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

Something looks wrong here. We call count within that function (unless we return null from the early bail

)

But in that case we should be checking for parts being null. because getting the 0th element on the line 244 of null also makes no sense

@MacJoom
Copy link
Contributor Author

MacJoom commented May 16, 2023

Yes OK - then we do not need to do a count again. I was just focusing on the part throwing the error... - and the section is not optional but mandatory

@alikon
Copy link
Contributor

alikon commented May 19, 2023

i've got a different error with postman without your PR

PHP Warning: Trying to access array offset on value of type null in /joomla-cms/administrator/components/com_fields/src/Model/GroupModel.php on line 244

image

@alikon
Copy link
Contributor

alikon commented May 19, 2023

btw applying the pr no more error

image

@alikon
Copy link
Contributor

alikon commented May 19, 2023

tested fields/groups/contacts/contact too

@alikon
Copy link
Contributor

alikon commented May 19, 2023

I have tested this item ✅ successfully on 0110c19


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

@richard67 richard67 added PHP 8.x PHP 8.x deprecated issues bug labels May 21, 2023
@richard67
Copy link
Member

@wilsonge Could you check and if ok add an approval with the review button so GitHub doesn’t show the unresolved review anymore? As far as I can see @MacJoom has solved your concerns.

@laoneo
Copy link
Member

laoneo commented May 22, 2023

The change looks ok, but I'm wondering why the context there is null?

@obuisard obuisard added this to the Joomla! 4.3.4 milestone Jul 20, 2023
@obuisard obuisard merged commit e8c9cf8 into joomla:4.3-dev Jul 20, 2023
@obuisard
Copy link
Contributor

Thank you Martin @MacJoom for the PR!

GeraintEdwards pushed a commit to GeraintEdwards/joomla-cms that referenced this pull request Aug 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug PHP 8.x PHP 8.x deprecated issues Webservices

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants