php - Getting error when trying to edit subpage in Grav ← (PHP, HTML)

Whenever I try to add or edit a subpage (i.e. a child page of the main page),

I am getting this error:

count(): Parameter must be an array or an object that implements Countable

Offending line is:

<div data-grav-array-type="container"{% if field.value_only %} 
     data-grav-array-mode="value_only"{% endif %}
     {{ value|length <= 1 ? ' class="one-child"' : '' }}>

This is happening in: /grav/templates/forms/fields/array/array.html.twig.

I'm not familiar enough with Grav to understand the stack and debug it.

Answer



Solution:

It looks like you upgrade to PHP 7.2. PHP changed count() behavior in the following RFC: https://wiki.php.net/rfc/counting_non_countables

Since then, calling count() with a parameter that is a scalar, null, or an object that doesn't implement Countable raises PHP warning like Warning: count(): Parameter must be an array or an object that implements Countable in %s on line %d.

Thus, since PHP 7.2 this will be considered as a bug in the code.

Examples:

https://github.com/twigphp/Twig/blob/2.x/lib/Twig/Node/Module.php#L370 https://github.com/twigphp/Twig/blob/2.x/lib/Twig/Extension/Core.php#L1117

You may want to use length() or try to convert your variable to iterable

Source