grav-plugin-admin icon indicating copy to clipboard operation
grav-plugin-admin copied to clipboard

Array to string conversion by switching PHP Version

Open chwebcloud opened this issue 2 years ago • 2 comments

I switched to PHP 8.0. On other projects it worked flawlessly. Everything in the admin area seems to work, except for the content management (pages). Temporarily I switched to PHP 7.4 to work with GRAV. However, in this project I get the following error:

An exception has been thrown during the rendering of a template ("Array to string conversion").

/user/plugins/form/templates/forms/fields/select/select.html.twig

                    value="{{ akey }}"
                >
                    {{ avalue|raw }}
                </option>
            {% elseif item_value is iterable %}
                {% set optgroup_label = item_value|keys|first %}
                <optgroup label="{{ optgroup_label|t|e('html_attr') }}">
                  {% for subkey, suboption in field.options[key][optgroup_label] %}
                      {% set subkey = subkey|string %}
                      {% set item_value = (field.selectize and field.multiple ? suboption : subkey)|string %}
                      {% set selected = (field.selectize ? suboption : subkey)|string %}
                      <option {% if subkey is same as (value) or (field.multiple and selected in value) %}selected="selected"{% endif %} value="{{ subkey }}">
                        {{ suboption|t|raw }}
                      </option>
                  {% endfor %}
                </optgroup>
            {% else %}
                {% set val = (field.selectize and field.multiple ? item_value : key)|string %}
                {% set selected = (field.selectize ? item_value : key)|string %}
                <option {% if val is same as (value) or (field.multiple and selected in value) %}selected="selected"{% endif %} value="{{ val }}">{{ item_value|t|raw }}</option>
            {% endif %}
        {% endfor %}

    </select>
</div>

{% endblock %}

Arguments

"An exception has been thrown during the rendering of a template ("Array to string conversion")."

chwebcloud avatar Mar 22 '23 10:03 chwebcloud

Runs fine for me on PHP 7.4, most likely you have some php cached by opcache. Try restarting your PHP-FPM (if you use that) or Apache.

rhukster avatar Mar 22 '23 16:03 rhukster

Yes, everything works fine in PHP 7.4. The error occurs with PHP 8.0 Thanks for your Support! Tom

chwebcloud avatar Mar 22 '23 17:03 chwebcloud