Sonataadminbundle: count() on null value

Created on 7 Feb 2019  路  4Comments  路  Source: sonata-project/SonataAdminBundle

Environment

PHP 7.2

Sonata packages

sonata-project/admin-bundle                  3.45.1             3.45.1             The missing Symfony Admin Generator
sonata-project/block-bundle                  3.14.0             3.14.0             Symfony SonataBlockBundle
sonata-project/cache                         2.0.1              2.0.1              Cache library
sonata-project/core-bundle                   3.15.1             3.15.1             Symfony SonataCoreBundle
sonata-project/datagrid-bundle               2.4.0              2.4.0              Symfony SonataDatagridBundle
sonata-project/doctrine-extensions           1.1.5              1.1.5              Doctrine2 behavioral extensions
sonata-project/doctrine-mongodb-admin-bundle 3.1.1              3.1.1              Symfony Sonata / Integrate Doctrine MongoDB ODM into the SonataAdminBundle
sonata-project/easy-extends-bundle           2.5.0              2.5.0              Symfony SonataEasyExtendsBundle
sonata-project/exporter                      2.0.1              2.0.1              Lightweight Exporter library
sonata-project/formatter-bundle              3.5.0              4.1.2              Symfony SonataFormatterBundle
sonata-project/intl-bundle                   2.5.0              2.5.0              Symfony SonataIntlBundle
sonata-project/jquery-bundle                 dev-master 8db2fbc dev-master 8db2fbc Symfony SonatajQueryBundle
Package sonata-project/jquery-bundle is abandoned, you should avoid using it. No replacement was suggested.
sonata-project/media-bundle                  3.18.1             3.18.1             Symfony SonataMediaBundle

PHP version

7.2

Subject

count() $array_or_countable parameter with PHP 7.2

Actual results

Symfony\Component\Debug\Exception\ContextErrorException:
Warning: count(): Parameter must be an array or an object that implements Countable

  at vendor/sonata-project/admin-bundle/src/Admin/AbstractAdmin.php:2911
bug unconfirmed

All 4 comments

I'm having the same issue with Sonata 3 (latest) & PHP7.2, same stack trace. The fix is pretty easy, I may open a PR.

Fixing it is pretty easy, you have to modify AbstractAdmin around line 2917:

        if (null !== $this->getBatchActions() && \count($this->getBatchActions()) > 0 && $this->hasRequest() && !$this->getRequest()->isXmlHttpRequest()) {
            $fieldDescription = // ...

Right now I'm swamped, I may be able to send a PR next week.

Today I could work on details. Actually, Sonata-provided AbstractAdmin::getBatchActions() implementation is safe. The issue is likely in your Admin class @thibaut-decherit, in mine I was returning null, which was OK before, but it is crashing on PHP 7.2.

This issue can be closed as it is user-side & not confirmed added.

Thank you for the feedback @romaricdrigon, I will look into it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

peter-gribanov picture peter-gribanov  路  3Comments

vazgen picture vazgen  路  4Comments

lukasz-zaroda picture lukasz-zaroda  路  3Comments

thomas2411 picture thomas2411  路  4Comments

ajeetvarma picture ajeetvarma  路  3Comments