Following the
#3334893 - SplObjectStorage::contains(): Argument #1 ($object) must be of type object, null given
🐛
SplObjectStorage::contains(): Argument #1 ($object) must be of type object, null given
Needs review
issue i'm just relaying on the Commerce price module.
Problem/Motivation
TypeError: SplObjectStorage::contains(): Argument #1 ($object) must be of type object, null given in
SplObjectStorage->contains() (line 61 of modules/contrib/price/src/CurrentLocale.php).
SplObjectStorage->contains(NULL) (Line: 61)
Drupal\price\CurrentLocale->getLocale() (Line: 29)
Drupal\price\CurrencyFormatter->__construct(Object, Object, Object) (Line: 259)
Drupal\Component\DependencyInjection\Container->createService(Array, 'price.currency_formatter') (Line: 177)
Drupal\Component\DependencyInjection\Container->get('price.currency_formatter', 1) (Line: 434)
Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters(Array) (Line: 237)
Drupal\Component\DependencyInjection\Container->createService(Array, 'private__pblaWpYeVnrYY3okgaekPk8g6VS4Dhh-H7J1KWrv0Vs') (Line: 449)
Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters(Array) (Line: 462)
Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters(Array) (Line: 237)
Drupal\Component\DependencyInjection\Container->createService(Array, 'serializer') (Line: 177)
Drupal\Component\DependencyInjection\Container->get('serializer', 1) (Line: 434)
Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters(Array) (Line: 237)
Drupal\Component\DependencyInjection\Container->createService(Array, 'api_toolkit.argument_resolver.api_request') (Line: 177)
Drupal\Component\DependencyInjection\Container->get('api_toolkit.argument_resolver.api_request', 1) (Line: 434)
Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters(Array) (Line: 462)
Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters(Array) (Line: 237)
Drupal\Component\DependencyInjection\Container->createService(Array, 'http_kernel.controller.argument_resolver') (Line: 177)
Drupal\Component\DependencyInjection\Container->get('http_kernel.controller.argument_resolver', 1) (Line: 434)
Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters(Array) (Line: 237)
Drupal\Component\DependencyInjection\Container->createService(Array, 'http_kernel.basic') (Line: 177)
Drupal\Component\DependencyInjection\Container->get('http_kernel.basic', 1) (Line: 434)
Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters(Array) (Line: 237)
Drupal\Component\DependencyInjection\Container->createService(Array, 'http_middleware.session') (Line: 177)
Drupal\Component\DependencyInjection\Container->get('http_middleware.session', 1) (Line: 434)
Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters(Array) (Line: 237)
Drupal\Component\DependencyInjection\Container->createService(Array, 'http_middleware.kernel_pre_handle') (Line: 177)
Drupal\Component\DependencyInjection\Container->get('http_middleware.kernel_pre_handle', 1) (Line: 434)
Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters(Array) (Line: 237)
Drupal\Component\DependencyInjection\Container->createService(Array, 'http_middleware.page_cache') (Line: 177)
Drupal\Component\DependencyInjection\Container->get('http_middleware.page_cache', 1) (Line: 434)
Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters(Array) (Line: 237)
Drupal\Component\DependencyInjection\Container->createService(Array, 'http_middleware.reverse_proxy') (Line: 177)
Drupal\Component\DependencyInjection\Container->get('http_middleware.reverse_proxy', 1) (Line: 434)
Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters(Array) (Line: 237)
Drupal\Component\DependencyInjection\Container->createService(Array, 'http_middleware.negotiation') (Line: 177)
Drupal\Component\DependencyInjection\Container->get('http_middleware.negotiation', 1) (Line: 434)
Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters(Array) (Line: 237)
Drupal\Component\DependencyInjection\Container->createService(Array, 'http_kernel') (Line: 177)
Drupal\Component\DependencyInjection\Container->get('http_kernel') (Line: 1405)
Drupal\Core\DrupalKernel->getHttpKernel() (Line: 713)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
require('/Users/dieterholvoet/Projects/sites-minsky/tmm-admin/web/index.php') (Line: 235)
Steps to reproduce
Create a service with the price formatter as a dependency, clear your caches, open a page where the service is used.
Proposed resolution
Services can be instantiated very early in the request, so we shouldn't assume a Request
object or even a negotiated language is available in the service constructor. $current_locale->getLocale()->getLocaleCode()
should be moved out of the constructor, the best way to me seems to add a getDefaultOptions
method to the upstream library, so we can fetch the default language as needed instead of when instantiating the service.