phpBB Debug - "Parameter must be an array or an object that implements Countable" [Solved!]

Get help with installation and running phpBB 3.2.x here. Please do not post bug reports, feature requests, or extension related questions here.
User avatar
ADPNene
Registered User
Posts: 4
Joined: Tue Dec 05, 2017 3:37 am
Location: Genom
Contact:

phpBB Debug - "Parameter must be an array or an object that implements Countable" [Solved!]

Post by ADPNene »

Hi folks, been a lurker, now a first time poster since creating my forum. I've UTFSE here and on Google for an answer to this problem, but I can't find the answer to this issue. The problem seems simple enough to fix, but it just doesn't make sense sense why it exists. If its a bug, I'd rather just disable the phpBB Debug from being visible to visitors and regular members.my

Here's the problem:

[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable

I've checked line 1275 in the Core.php and this is what its pointing to:

Code: Select all

// add multibyte extensions if possible
if (function_exists('mb_get_info')) {
    /**
     * Returns the length of a variable.
     *
     * @param Twig_Environment $env
     * @param mixed            $thing A variable
     *
     * @return int The length of the value
     */
    function twig_length_filter(Twig_Environment $env, $thing)
    {
        if (is_scalar($thing)) {
            return mb_strlen($thing, $env->getCharset());
        }

        if (is_object($thing) && method_exists($thing, '__toString') && !$thing instanceof \Countable) {
            return mb_strlen((string) $thing, $env->getCharset());
        }

        return count($thing);
    }
The last line "return count($thing);" is line #1275 :?

I'm not familiar with what "twig" even is.



Support Request Template
What version of phpBB are you using? phpBB 3.2.1
What is your board's URL? http://www.romanova.club/forum/
Who do you host your board with? www.namecheap.com
How did you install your board? I used the download package from phpBB.com
What is the most recent action performed on your board? Fresh Install
Is registration required to reproduce this issue? No
Do you have any MODs installed? No
Do you have any extensions installed? No
What styles do you currently have installed? prosilver
What language(s) is your board currently using? English
Which database type/version are you using? MariaDB
What is your level of experience? New to PHP and phpBB
What actions did you take (updating your board; installing a MOD, style or extension; etc.) prior to this problem becoming noticeable? Prior to noticing this problem, everything worked fine. After I updated my linux system and configured a simple stateful firewall/iptables on my webserver, the problem was noticed.

I uninstalled the only extension [VigLink] and disabled the prosilver theme, but I still get the following two messages back to back on the forum.
Please describe your problem. The error messages appear at the very top of the forum - above the header, also in the ADP General tab in the upper left corner [above "Quick Access", but below "You are logged in as:"], it shows after each forum desciption, and in the "forum birthdays" area:

[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable

Here's how it looks from within an existing thread: https://i.imgur.com/MZ4dK2q.png

Lastly, it appears I cannot post a new thread inside a forum I just created: https://i.imgur.com/Ea8MXin.png
Generated by SRT Generator


Parameter must be an array or an object that implements Countable
Last edited by ADPNene on Thu Dec 14, 2017 3:43 am, edited 1 time in total.
I live up to my family name through my good looks and amazing brain!
User avatar
wang5555
Translator
Posts: 620
Joined: Wed Oct 27, 2004 2:57 pm
Location: Taiwan

Re: phpBB Debug - "Parameter must be an array or an object that implements Countable"

Post by wang5555 »

ADPNene wrote: Tue Dec 05, 2017 4:09 am
Here's the problem:

[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable
The day before yesterday, I upgraded PHP from 7.1.12 to 7.2.0, a similar problem occurred.

Perhaps, in the future phpBB 3.2.2 can successfully solve this problem.

At this point, use PHP 7.1.12 version more appropriate. ;)
It is more blessed to give than to reveive, good luck! ^_^
Welcome to my forum
https://wang5555.dnsfor.me/phpBB3/
Frank Rizzo
Registered User
Posts: 149
Joined: Sun Jan 05, 2003 11:10 pm
Contact:

Re: phpBB Debug - "Parameter must be an array or an object that implements Countable"

Post by Frank Rizzo »

I'm surprised there are not hundreds of posts like this from shared hosting sites that have had php upgraded to 7.2

The problem was first notified earlier in the year

https://tracker.phpbb.com/browse/PHPBB3-14972

That states it has been fixed with 3.3.0-a1, which is no help to us here. I will try and chase it up in area51 to see what the fix was.
User avatar
warmweer
Jr. Extension Validator
Posts: 11235
Joined: Fri Jul 04, 2003 6:34 am
Location: Van Allen Bel ... gium
Contact:

Re: phpBB Debug - "Parameter must be an array or an object that implements Countable"

Post by warmweer »

ADPNene wrote: Tue Dec 05, 2017 4:09 am...
and disabled the prosilver theme...
Is this a mistake in what you wrote or is it really possible to disable the only present theme and still run the forum? ( I'm not taunting or anything: I really don't know but it doesn't seem logical to me).

edited for spelling mistakes (well ... at least the ones I noticed)
Last edited by warmweer on Fri Dec 08, 2017 7:21 pm, edited 1 time in total.
Spelling is freeware, which means you can use it for free.
On the other hand, it is not open source, which means you cannot change it or publish it in a modified form.


Time flies like an arrow, but fruit flies like a banana.
User avatar
RMcGirr83
Former Team Member
Posts: 22016
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr

Re: phpBB Debug - "Parameter must be an array or an object that implements Countable"

Post by RMcGirr83 »

Former Modifications/Extensions Team Member | My extensions | github | All requests for support via PM will be ignored
Appreciate the extensions/mods/support then buy me a beer Image
Frank Rizzo
Registered User
Posts: 149
Joined: Sun Jan 05, 2003 11:10 pm
Contact:

Re: phpBB Debug - "Parameter must be an array or an object that implements Countable"

Post by Frank Rizzo »

The solution to this problem is with twig and not phpbb. The version of twig in use has coding error with the count() function, which is now being flagged by php 7.2. The solution is to update twig, or for a quick fix just edit the core.php file as stated here:

https://area51.phpbb.com/phpBB/viewtopi ... 61#p305156
User avatar
rleeden
Registered User
Posts: 23
Joined: Sun Jul 23, 2006 11:57 am
Contact:

Re: phpBB Debug - "Parameter must be an array or an object that implements Countable"

Post by rleeden »

Frank Rizzo wrote: Sat Dec 09, 2017 11:36 am .... or for a quick fix just edit the core.php file as stated here:

https://area51.phpbb.com/phpBB/viewtopi ... 61#p305156
Thanks - I can confirm that for me, this quick fix did the trick.

The core.php file mentioned above is: vendor/twig/twig/lib/Twig/Extension/Core.php
User avatar
rleeden
Registered User
Posts: 23
Joined: Sun Jul 23, 2006 11:57 am
Contact:

Re: phpBB Debug - "Parameter must be an array or an object that implements Countable"

Post by rleeden »

Although, looks like there's another problem as I get this error:

Code: Select all

[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/template/context.php on line 203: sizeof(): Parameter must be an array or an object that implements Countable
When in the ACP and looking at my 'PHP Information' page.
User avatar
wang5555
Translator
Posts: 620
Joined: Wed Oct 27, 2004 2:57 pm
Location: Taiwan

Re: phpBB Debug - "Parameter must be an array or an object that implements Countable"

Post by wang5555 »

Frank Rizzo wrote: Sat Dec 09, 2017 11:36 am The solution to this problem is with twig and not phpbb. The version of twig in use has coding error with the count() function, which is now being flagged by php 7.2. The solution is to update twig, or for a quick fix just edit the core.php file as stated here:

https://area51.phpbb.com/phpBB/viewtopi ... 61#p305156
Good job! :D
It is more blessed to give than to reveive, good luck! ^_^
Welcome to my forum
https://wang5555.dnsfor.me/phpBB3/
User avatar
ADPNene
Registered User
Posts: 4
Joined: Tue Dec 05, 2017 3:37 am
Location: Genom
Contact:

Re: phpBB Debug - "Parameter must be an array or an object that implements Countable"

Post by ADPNene »

warmweer wrote: Fri Dec 08, 2017 7:05 pm
ADPNene wrote: Tue Dec 05, 2017 4:09 am...
and disabled the prosilver theme...
Is this a mistake in what you wrote or is it really possible to disable the only present theme and still run the forum? ( I'm not taunting or anything: I really don't know but it doesn't seem logical to me).

edited for spelling mistakes (well ... at least the ones I noticed)
This was a mistake on my part, as I meant prosilver Special Edition.
Frank Rizzo wrote: Sat Dec 09, 2017 11:36 am The solution to this problem is with twig and not phpbb. The version of twig in use has coding error with the count() function, which is now being flagged by php 7.2. The solution is to update twig, or for a quick fix just edit the core.php file as stated here:

https://area51.phpbb.com/phpBB/viewtopi ... 61#p305156
Frank Rizzo wrote:I edited the core.php file, changing the section for twig_length_filter from:

Code: Select all

    /**
     * Returns the length of a variable.
     *
     * @param Twig_Environment $env
     * @param mixed            $thing A variable
     *
     * @return int The length of the value
     */
    function twig_length_filter(Twig_Environment $env, $thing)
    {
        if (is_scalar($thing)) {
            return mb_strlen($thing, $env->getCharset());
        }

        if (is_object($thing) && method_exists($thing, '__toString') && !$thing instanceof \Countable) {
            return mb_strlen((string) $thing, $env->getCharset());
        }

        return count($thing);
    }
to

Code: Select all

/**
     * Returns the length of a variable.
     *
     * @param Twig_Environment $env
     * @param mixed            $thing A variable
     *
     * @return int The length of the value
     */
    function twig_length_filter(Twig_Environment $env, $thing)
    {
        if (null === $thing) {
            return 0;
        }
        if (is_scalar($thing)) {
            return mb_strlen($thing, $env->getCharset());
        }
        if (is_object($thing) && method_exists($thing, '__toString') && !$thing instanceof \Countable) {
            return mb_strlen((string) $thing, $env->getCharset());
        }
        if ($thing instanceof \Countable || is_array($thing)) {
            return count($thing);
        }
        return 1;
    }

I tried this method and resolved my issue. Thanks for your support guys! I knew I could count on you. :D
I live up to my family name through my good looks and amazing brain!
User avatar
danger89
Registered User
Posts: 14
Joined: Fri Oct 27, 2006 8:17 pm
Name: Melroy van den Berg
Contact:

Re: phpBB Debug - "Parameter must be an array or an object that implements Countable" [Solved!]

Post by danger89 »

Well.. What is the fastest solution?? I think I need to disable error logging. Or can I upgrade to some phpBB version??

I updated includes/startup.php, replaced current error_reporting with:
error_reporting(0);

Fully disables errors, since I don't want any errors during production! Maybe add this option is the config file/ACP?
Frank Rizzo
Registered User
Posts: 149
Joined: Sun Jan 05, 2003 11:10 pm
Contact:

Re: phpBB Debug - "Parameter must be an array or an object that implements Countable" [Solved!]

Post by Frank Rizzo »

I had a few other problems with 3.2.1 and PHP 7.2, such as a 500 error on user registration.

The fastest solution for me was to install 3-3-0-a1-dev. All error messages gone but obviously there are risks with an alpha version (but then it helps give feedback to the developers).
PeterPan99999
Registered User
Posts: 1
Joined: Thu Mar 22, 2018 2:17 pm

Re: phpBB Debug - "Parameter must be an array or an object that implements Countable"

Post by PeterPan99999 »

rleeden wrote: Sat Dec 09, 2017 12:57 pm Although, looks like there's another problem as I get this error:

Code: Select all

[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/template/context.php on line 203: sizeof(): Parameter must be an array or an object that implements Countable
When in the ACP and looking at my 'PHP Information' page.
Indeed:

Code: Select all

[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/template/context.php on line 204: count(): Parameter must be an array or an object that implements Countable
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions_acp.php on line 137: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3268)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions_acp.php on line 137: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3268)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions_acp.php on line 137: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3268)
This warning message still occurs on 3.2.2 and PHP 7.2.1. In my opinion this is a case where this new count( ) warning message in PHP 7.2 actually has its use, since this warning is a bug in phpBB and not simply a count( ) / isset( ) / sizeof( ) void warning message.

It occurs @ ACP System Tab, and ONLY in the four items under "General Tasks" section on the left.

https://github.com/phpbb/phpbb/blob/mas ... ontext.php
https://github.com/phpbb/phpbb/blob/3.2 ... ontext.php
The last update on this context.php was done on 1 Jan 2018, and this issue seems NOT resolved in future release phpBB 3.2.3 yet, since there is no future branch available for this file on GitHub.

Code: Select all

Line 203: $block = &$block[$name];
Line 204: $index = (!$pos || strpos($blocks[$i], '[]') === $pos) ? (count($block) - 1) : (min((int) substr($blocks[$i], $pos + 1, -1), count($block) - 1));
It seems in /phpbb/template/context.php in the for( )-loop around line 204, at some point there is no array assigned to $block and therefore the debug warning pops. I've tried debugging it but it goes over my head. It's not a very simple solution I'd say, since you need good understanding of where all the assinged values in $block come from.

I'm not sure if this bug is already reported in the bug tracker, but if anyone would like to post it, please feel free to do so. I'm more of a lurker, but I did my 2 cents for the community with this message.
JoshMorgan
Registered User
Posts: 1
Joined: Wed Nov 21, 2018 8:20 pm

Re: phpBB Debug - "Parameter must be an array or an object that implements Countable" [Solved!]

Post by JoshMorgan »

I can confirm that this bug is NOT "solved" and still exists in phpbb 3.2.4 with PHP Version 7.2. PHP 7.1 is fine but PHP 7.2 throws the following errors on any of the 4 GENERAL TASKS in the SYSTEM tab (Spiders/Robots, Mass email, PHP information and Manage report/denial reasons).

Code: Select all

[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/template/context.php on line 204: count(): Parameter must be an array or an object that implements Countable
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions_acp.php on line 137: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3314)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions_acp.php on line 137: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3314)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions_acp.php on line 137: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3314)
The errors exist on both of the boards that I administer running PHP 7.2.
RobiX
Registered User
Posts: 110
Joined: Thu Oct 05, 2017 9:59 am

Re: phpBB Debug - "Parameter must be an array or an object that implements Countable" [Solved!]

Post by RobiX »

i can agree to JoshMorgan

same here (phpBB 3.2.4 + php 7.2.4):

Code: Select all

[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/template/context.php on line 204: count(): Parameter must be an array or an object that implements Countable
Locked

Return to “[3.2.x] Support Forum”