J3 Issue ?
avatar VisiGod
VisiGod
28 Dec 2018

Steps to reproduce the issue

Use php version 7.3. In any view that has the code:
if (count($errors = $this->get('Errors'))) {
a warning appears that says "Warning: count(): Parameter must be an array or an object that implements Countable in [put view file here]"

After some testing, I was able to replace the code to:
if ($this->get('Errors') && count($errors = $this->get('Errors'))) {

and no longer have the warning

Expected result

No warning on code

Actual result

System information (as much as possible)

Additional comments

avatar VisiGod VisiGod - open - 28 Dec 2018
avatar joomla-cms-bot joomla-cms-bot - labeled - 28 Dec 2018
avatar VisiGod VisiGod - change - 28 Dec 2018
Title
"Warning: count(): Parameter must be an array or an object that implements Countable" in J3 with PHP 7.2
[3] "Warning: count(): Parameter must be an array or an object that implements Countable" in J3 with PHP 7.2
avatar VisiGod VisiGod - edited - 28 Dec 2018
avatar VisiGod VisiGod - change - 28 Dec 2018
Title
[3] "Warning: count(): Parameter must be an array or an object that implements Countable" in J3 with PHP 7.2
"Warning: count(): Parameter must be an array or an object that implements Countable" in J3 with PHP 7.2
avatar VisiGod VisiGod - edited - 28 Dec 2018
avatar Quy Quy - change - 28 Dec 2018
Title
"Warning: count(): Parameter must be an array or an object that implements Countable" in J3 with PHP 7.2
"Warning: count(): Parameter must be an array or an object that implements Countable" in J3 with PHP 7.3
avatar joomla-cms-bot joomla-cms-bot - edited - 28 Dec 2018
avatar ReLater
ReLater - comment - 2 Jan 2019

After some testing, I was able to replace the code

Could you please inform us where you got the error and in which file you've added your fix.

avatar ReLater
ReLater - comment - 2 Jan 2019

Ah, sorry. I didn't see

Use php version 7.3. In any view that has the code:

avatar VisiGod
VisiGod - comment - 2 Jan 2019

I can do a list of files that produce that error if needed.

avatar ReLater
ReLater - comment - 2 Jan 2019

I would make a single Pull Request first (before I waste my time with lots of files) and wait for comments of the experts here. If they say "Solution is OK" then one could fix all other codes.

Start your Pull Request title with a [RFC] (request for comments).

HowTo: Using the Github UI to Make Pull Requests

avatar trailsnail
trailsnail - comment - 5 Jan 2019

@VisiGod
if ($this->get('Errors') && count($errors = $this->get('Errors'))) {
is not the best solution.

I would use if (!empty($this->get('Errors'))) {

or if $errors is used later in code:

$errors = $this->get('Errors');
if (!empty($errors)) {

I do not know the code, but I'm always in favor of calling a method only once and using its result.
It may be that in your example the double calling of $this->get('Errors') will execute function code twice which would not be the best for performance reasons

2nd solution would be, if $this->get('Errors') will always return array() if no errors exist. So errors on all callsites will be fixed. but as I said - I don't know the code ;)

avatar VisiGod
VisiGod - comment - 11 Feb 2019

This was found when testing against PHP 7.3 which is not widely used on production. Since I was testing the component on 7.3, this core error appeared.

From: Phil Taylor notifications@github.com
Sent: Sunday, February 10, 2019 18:31
To: joomla/joomla-cms joomla-cms@noreply.github.com
Cc: VisiGod visigod@visigod.com; Mention mention@noreply.github.com
Subject: Re: [joomla/joomla-cms] "Warning: count(): Parameter must be an array or an object that implements Countable" in J3 with PHP 7.3 (#23377)

Apart from just doing a code review itself, have you actually received this error message output on a live Joomla site ?

Are you able to provide a replicateable test case?

I understand the PHP 7 compatibility issue well - but Im struggling to understand why we are not receiving more reports about the error... maybe Joomla is never running those areas of code?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub #23377 (comment) , or mute the thread https://github.com/notifications/unsubscribe-auth/ArXTs0QNFieVtXxd-KqGoJOSfJmVNL_Wks5vMGV6gaJpZM4ZkSSE . https://github.com/notifications/beacon/ArXTs6X64YXtUrtI9VR8_9vFPYpOjAsVks5vMGV6gaJpZM4ZkSSE.gif

avatar franz-wohlkoenig franz-wohlkoenig - change - 4 Mar 2019
Status New Discussion
avatar franz-wohlkoenig franz-wohlkoenig - change - 4 Apr 2019
Labels Added: J3 Issue
avatar franz-wohlkoenig franz-wohlkoenig - labeled - 4 Apr 2019
avatar SharkyKZ
SharkyKZ - comment - 20 May 2019

I can't reproduce this on core. But count() calls can be removed anyways if their result is not used elsewhere.

avatar franz-wohlkoenig
franz-wohlkoenig - comment - 20 May 2019

closed for Reason stated above.

avatar franz-wohlkoenig franz-wohlkoenig - close - 20 May 2019
avatar franz-wohlkoenig franz-wohlkoenig - change - 20 May 2019
Status Discussion Closed
Closed_Date 0000-00-00 00:00:00 2019-05-20 06:43:58
Closed_By franz-wohlkoenig

Add a Comment

Login with GitHub to post a comment