PHP 7.2 throws various errors due to the way count() is now handled.
e.g. when browsing the forum index:
My Forum Section
My Forum Description [phpbb Debug] 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 error was first reported here:
https://tracker.phpbb.com/browse/PHPBB3-14972
but that states that it has been fixed for 3.3.0-a1
Can the fix be applied to 3.2? What was the fix exactly?
What's the Fix for PHP 7.2 Count() Issue?
Forum rules
Please do not post support questions regarding installing, updating, or upgrading phpBB 3.3.x. If you need support for phpBB 3.3.x please visit the 3.3.x Support Forum on phpbb.com.
If you have questions regarding writing extensions please post in Extension Writers Discussion to receive proper guidance from our staff and community.
Please do not post support questions regarding installing, updating, or upgrading phpBB 3.3.x. If you need support for phpBB 3.3.x please visit the 3.3.x Support Forum on phpbb.com.
If you have questions regarding writing extensions please post in Extension Writers Discussion to receive proper guidance from our staff and community.
-
- Registered User
- Posts: 17
- Joined: Mon Nov 30, 2015 2:45 pm
Re: What's the Fix for PHP 7.2 Count() Issue?
This looks like the PR - https://github.com/phpbb/phpbb/commit/7 ... d0c1f7a815
David
Remember: You only know what you know -
and you do not know what you do not know!
Remember: You only know what you know -
and you do not know what you do not know!
-
- Registered User
- Posts: 17
- Joined: Mon Nov 30, 2015 2:45 pm
Re: What's the Fix for PHP 7.2 Count() Issue?
Having had a look at this it's obvious the specific error I quoted above is due to twig and not phpbb.
This solves the twig\core.php error:
https://github.com/twigphp/Twig/commit/ ... 0468eef74f
So the solution for this is for the phpBB package to have the version of twig that has the updated files.
This solves the twig\core.php error:
https://github.com/twigphp/Twig/commit/ ... 0468eef74f
So the solution for this is for the phpBB package to have the version of twig that has the updated files.
-
- Registered User
- Posts: 17
- Joined: Mon Nov 30, 2015 2:45 pm
Re: What's the Fix for PHP 7.2 Count() Issue?
I edited the core.php file, changing the section for twig_length_filter from:
to:
That fixed the problem.
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);
}
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;
}
Re: What's the Fix for PHP 7.2 Count() Issue?
I think that phpbb3.2 only supports until 7.1
phpBB3.3 suppots from 7.0 to 7.2
phpBB3.3 suppots from 7.0 to 7.2
Re: What's the Fix for PHP 7.2 Count() Issue?
So phpbb will not support the latest php version ? That is strange considering that 3.3. is not released and not even in alpha.
- DavidIQ
- Customisations Team Leader
- Posts: 1904
- Joined: Thu Mar 02, 2006 4:29 pm
- Location: Earth
- Contact:
Re: What's the Fix for PHP 7.2 Count() Issue?
You must have missed or ignored the part about it being a Twig error and not phpbb... The fix would obviously be to update Twig, except that it's not that simple. Along with the fix above there would end up being other core changes needed just to support the version of Twig where they fixed PHP 7.2 compatibility.koraldon wrote: Wed Dec 20, 2017 4:19 pm So phpbb will not support the latest php version ? That is strange considering that 3.3. is not released and not even in alpha.
Re: What's the Fix for PHP 7.2 Count() Issue?
Okay, but the bottom line is the same. It means that in the near future phpbb is not compatible with the latest version of php.
I also see the fix by Frank, can't it be implemented as a stopgap measure?
I also see the fix by Frank, can't it be implemented as a stopgap measure?
- DavidIQ
- Customisations Team Leader
- Posts: 1904
- Joined: Thu Mar 02, 2006 4:29 pm
- Location: Earth
- Contact:
Re: What's the Fix for PHP 7.2 Count() Issue?
That's in the actual Twig package, a dependency, and not in the phpBB code.
Re: What's the Fix for PHP 7.2 Count() Issue?
3.2.x won't support PHP 7.2+ for technical reasons, so the answer is no, it can't.