Prestashop: Cannot use object of type ParameterBag as array

Created on 4 Oct 2019  路  5Comments  路  Source: PrestaShop/PrestaShop

I get exception when saving a product: Cannot use object of type ParameterBag as array.

[Tue Oct 01 14:45:05.873957 2019] [php7:error] [pid 15296] [client 172.19.0.2:47756] script '/var/www/html/admin/themes/new-theme/public/index.php' not found or unable to stat, referer: https://myshop.com/admin/index.php/sell/catalog/products/9018?_token=Tl8ItvVRfaL46AdjUjhk5F52XFRuJjsQPfPQPS7X9FY
[Tue Oct 01 14:45:15.704399 2019] [php7:error] [pid 19] [client 172.19.0.2:47768] PHP Fatal error:  Uncaught Symfony\\Component\\Debug\\Exception\\FatalThrowableError: Cannot use object of type Symfony\\Component\\HttpFoundation\\ParameterBag as array in /var/www/html/src/Adapter/Security/Admin.php:91
Stack trace:
#0 /var/www/html/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/EventDispatcher.php(212): PrestaShop\\PrestaShop\\Adapter\\Security\\Admin->onKernelRequest(Object(Symfony\\Component\\HttpKernel\\Event\\GetResponseEvent), 'kernel.request', Object(Symfony\\Component\\EventDispatcher\\ContainerAwareEventDispatcher))
#1 /var/www/html/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/EventDispatcher.php(44): Symfony\\Component\\EventDispatcher\\EventDispatcher->doDispatch(Array, 'kernel.request', Object(Symfony\\Component\\HttpKernel\\Event\\GetResponseEvent))
#2 /var/www/html/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php(127): Symfony\\Component\\EventDispatcher\\EventDispatcher->dispatch('kernel.request', Object(Symfony\\Component\\HttpKernel\\Event\\GetResponseEvent))
#3 /var/www/h in /var/www/html/src/Adapter/Security/Admin.php on line 91, referer: https://myshop.com/admin/index.php/sell/catalog/products/9018?_token=Tl8ItvVRfaL46AdjUjhk5F52XFRuJjsQPfPQPS7X9FY

This was caused by a module trying to call a function that did not exist by mistake in the name. It was quite difficult for me to find the problem since the error log did not show anything about this.

We can see that $attributes prop of class Request is of type ParameterBag, and ParameterBag (latest and previous versions) does not implement arrayaccess

PR: https://github.com/PrestaShop/PrestaShop/pull/15805

Additional information
PrestaShop version: 1.7.6.1
PHP version: 7.1.32

1.7.6.1 BO Bug Fixed PR available Products

All 5 comments

Hi @davidglezz,

Could you please provide the exact steps to reproduce the issue & a demo module to test it.

Thanks!

Sorry, I have no idea how to reproduce it. and I don't have time to try to find a way to reproduce it.

But I think the description should be enough. Ask if you have any questions.

Look at the pull request changes to verify that it is a very simple technical fix.
The Stack trace explains what happens. I have also tried to explain in the description.

Ping @PrestaShop/prestashop-core-developers what do you think?

Thanks!

The fix seems legit, ParameterBag couldn't be interpreted as array.
Because we maybe never run in SUB_REQUEST context, this is why we never had this error :thinking:

Similar issue for me today when trying to access to admin. I had a PS 1.7.5.2 on my local environment and I tried to update files and database from another environment in PS 1.7.6.1 and now I have the following:

2019/10/08 17:28:36 [error] 500#0: *211 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Uncaught Symfony\Component\Debug\Exception\FatalThrowableError: Cannot use object of type Symfony\Component\HttpFoundation\ParameterBag as array in /vagrant/httpdocs/src/Adapter/Security/Admin.php:91

Stack trace:
#0 /vagrant/httpdocs/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/EventDispatcher.php(212): PrestaShop\PrestaShop\Adapter\Security\Admin->onKernelRequest(Object(Symfony\Component\HttpKernel\Event\GetResponseEvent), 'kernel.request', Object(Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher))
#1 /vagrant/httpdocs/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/EventDispatcher.php(44): Symfony\Component\EventDispatcher\EventDispatcher->doDispatch(Array, 'kernel.request', Object(Symfony\Component\HttpKernel\Event\GetResponseEvent))
#2 /vagrant/httpdocs/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php(127): Symfony\Component\EventDispatcher\EventDispatcher->dispatch('kernel.request', Object(Symfony\Componen" while reading response header from upstream, client: 192.168.1.1, server: dev.prestashop.net, request: "GET /adminXXX/ HTTP/1.1", upstream: "fastcgi://unix:/var/run/vagrant.sock:", host: "dev.prestashop.net"

EDIT: @davidglezz's PR #15805 fixes this but now I have another Fatal error:

2019/10/08 17:47:47 [error] 500#0: *221 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Uncaught Symfony\Component\Debug\Exception\FatalThrowableError: Type error: Too few arguments to function PrestaShopBundle\Twig\LayoutExtension::__construct(), 2 passed in /vagrant/httpdocs/var/cache/prod/ContainerEhonuft/appProdProjectContainer.php on line 1835 and exactly 4 expected in /vagrant/httpdocs/src/PrestaShopBundle/Twig/LayoutExtension.php:61
Stack trace:
#0 /vagrant/httpdocs/var/cache/prod/ContainerEhonuft/appProdProjectContainer.php(1835): PrestaShopBundle\Twig\LayoutExtension->__construct(Object(PrestaShop\PrestaShop\Adapter\LegacyContext), 'prod')
#1 /vagrant/httpdocs/var/cache/prod/ContainerEhonuft/appProdProjectContainer.php(1967): ContainerEhonuft\appProdProjectContainer->getPrestashop_Twig_Extension_LayoutService()
#2 /vagrant/httpdocs/var/cache/prod/ContainerEhonuft/getTwig_Controller_ExceptionService.php(8): ContainerEhonuft\appProdProjectContainer->getTwigService()
#3 /vagrant/httpdocs/var/cache/prod/ContainerEhonuft/appProdProjectContainer.php(1151): r" while reading response header from upstream, client: 192.168.1.1, server: dev.prestashop.net, request: "GET /adminXXX/ HTTP/1.1", upstream: "fastcgi://unix:/var/run/vagrant.sock:", host: "dev.prestashop.net"
Was this page helpful?
0 / 5 - 0 ratings