ElkArte Community

Title: 1.1.1 php7.2 error
Post by: badmonkey on December 17, 2017, 10:32:14 am
Not sure if this really belongs in bugz or not.  emanuele will undoubtedly choose wisely.   ;)  


Anyway, when attempting to read PMs in 1.1.1 on php7.2, the following error occurs:


Code: [Select]
count(): Parameter must be an array or an object that implements Countable
Title: Re: 1.1.1 php7.2 error
Post by: emanuele on December 17, 2017, 02:06:22 pm
Does it say also the file and the line of the error?
Title: Re: 1.1.1 php7.2 error
Post by: radu81 on December 17, 2017, 05:34:06 pm
I can confirm, I have the same error. I try to give more information: I set PM as conversations, with PHP 7.1 I see all messages of the conversation, with PHP 7.2 I only see the first message of the conversation, and after that the error mentioned by @badmonkey

I attach a couple of screenshots:
(Link-5348)  (Link-5350)

In elkarte log there is no error using php 7.1, with 7.2 I get:

Type of error: General
Warning: count(): Parameter must be an array or an object that implements Countable
http://...index.php?action=pm;pmid=2429;kstart;f=inbox;start=30;sort=date;asc
File: ...sources/controllers/PersonalMessage.controller.php
Line: 3094
Title: Re: 1.1.1 php7.2 error
Post by: tino on December 17, 2017, 06:14:01 pm
I think the first count on that line isn’t required. Or at least that’s what’s throwing the error
Title: Re: 1.1.1 php7.2 error
Post by: live627 on December 17, 2017, 11:34:50 pm
I don't run PHP 7.2 yet, but I quickly looked through the relevant code and came up with the fix below.

https://github.com/elkarte/Elkarte/pull/3081/files
Title: Re: 1.1.1 php7.2 error
Post by: emanuele on December 20, 2017, 09:00:22 am
I lost the reply...
OMG again PMs... :'(
My eyes are already bleeding!! xD
Title: Re: 1.1.1 php7.2 error
Post by: live627 on December 20, 2017, 11:20:37 pm
haha

@badmonkey @radu81 did it work?
Title: Re: 1.1.1 php7.2 error
Post by: radu81 on December 21, 2017, 03:25:24 am
Thanks @live627‍ , nothing changed, I still see the error
Title: Re: 1.1.1 php7.2 error
Post by: live627 on December 21, 2017, 05:28:03 am
can you also add https://github.com/elkarte/Elkarte/pull/3081/commits/fa78e4b2db21ec6cdd7fe866a62839dfd831037f ?
Title: Re: 1.1.1 php7.2 error
Post by: Feline on December 21, 2017, 06:38:34 am
If you use count on php7.* check is the $var a array with a simple is_array($var) ..
like if(is_array($var) && count($var) = 2)

Fel
Title: Re: 1.1.1 php7.2 error
Post by: radu81 on December 21, 2017, 09:08:20 am
I still see that error: count(): Parameter must be an array or an object that implements Countable
Title: Re: 1.1.1 php7.2 error
Post by: badmonkey on January 25, 2018, 04:01:32 pm
Confirmed the error persists. 
Title: Re: 1.1.1 php7.2 error
Post by: emanuele on January 25, 2018, 04:55:07 pm
Let's try this: in PersonalMessage.subs.php, find:
Code: [Select]
	$message_labels = array();
and add after it:
Code: [Select]
	foreach ($all_pms as $pmid)
{
$message_labels[$pmid] = array();
}
Title: Re: 1.1.1 php7.2 error
Post by: radu81 on January 25, 2018, 06:36:12 pm
Yes, that works fine, thanks  8)
Title: Re: 1.1.1 php7.2 error
Post by: badmonkey on January 25, 2018, 07:59:22 pm
Still getting the error here.  PHP 7.2.1, if that matters.   ;)
Title: Re: 1.1.1 php7.2 error
Post by: emanuele on January 26, 2018, 03:34:39 am
Even applying all the changes suggested by live and me?
Title: Re: 1.1.1 php7.2 error
Post by: badmonkey on January 26, 2018, 07:00:28 am
Quote from: emanuele – Even applying all the changes suggested by live and me?

Applying the changes on github as well as the last change you posted, correct. Even emptied the cache.

Sanity check: I'll double check the edits later this morning to be absolutely certain I didn't goof. I've done dumber things.  ;D
Title: Re: 1.1.1 php7.2 error
Post by: badmonkey on January 26, 2018, 10:17:49 am
Update: another php restart did the trick!  Thanks eman!   ;)
Title: Re: 1.1.1 php7.2 error
Post by: emanuele on January 28, 2018, 06:14:49 pm
@badmonkey  could you please can you please check which line the error occurs?

ETA: seems I missed your last reply... :-[
hmm... interesting, maybe the opcache did not pick up the changes?
Title: Re: 1.1.1 php7.2 error
Post by: badmonkey on January 28, 2018, 07:00:48 pm
That was the running theory here as well.  Thanks again for the help!
Title: Re: 1.1.1 php7.2 error
Post by: live627 on January 28, 2018, 09:39:22 pm
Does clearing the forum (not browser!) cache also invalidate the opcode cache?
Title: Re: 1.1.1 php7.2 error
Post by: emanuele on January 29, 2018, 03:38:06 am
Good question... I don't think so.
As far as I remember the only time opcache is invalidated is when writing to Settings.php... but I may be wrong.