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
No warning on code
Title |
|
Title |
|
Title |
|
Ah, sorry. I didn't see
Use php version 7.3. In any view that has the code:
I can do a list of files that produce that error if needed.
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).
@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 ;)
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
Status | New | ⇒ | Discussion |
Labels |
Added:
J3 Issue
|
I can't reproduce this on core. But count()
calls can be removed anyways if their result is not used elsewhere.
closed for Reason stated above.
Status | Discussion | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2019-05-20 06:43:58 |
Closed_By | ⇒ | franz-wohlkoenig |
Could you please inform us where you got the error and in which file you've added your fix.