Skip to content

PHP 8.5 deprecation warning: null locale used as array key in Magento\Framework\Locale\Currency #40814

@naseeraslam

Description

@naseeraslam

Preconditions and environment

📄 Description

Preconditions

  • Magento Open Source: 2.4.9
  • PHP Version: 8.5
  • Environment: CLI and/or web execution (cron, currency formatting, or order flows)
  • No custom modification in Magento\Framework\Locale\Currency

🧩 Problem

When executing Magento code that triggers currency resolution (e.g. getCurrencySymbol()), PHP 8.5 emits a deprecation warning:

Deprecated: Using null as array offset is deprecated

The issue originates from Magento\Framework\Locale\Currency::getCurrency().


🔍 Affected Code

In vendor/magento/framework/Locale/Currency.php:

self::$_currencyCache[$this->_localeResolver->getLocale() ?? ''][$currency] = $currencyObject;

Steps to reproduce

🔁 Steps to Reproduce

  1. Install Magento Open Source 2.4.9
  2. Configure any store locale
  3. Run any operation that uses currency formatting, for example:
$this->currency->getCurrencySymbol();
  1. Observe PHP 8.5 deprecation warnings

📌 Impact

  • PHP 8.5 deprecation warnings in CLI and web requests
  • Affects all currency formatting operations
  • Impacts logs, monitoring systems, and cron execution output
  • Breaks clean execution in strict environments

📎 Notes

  • Issue is reproducible only on PHP 8.5
  • PHP 8.1–8.4 may not always show warnings depending on configuration
  • Root cause is unsafe array key usage with nullable locale value

Expected result

No PHP warnings should be triggered.

🛠 Suggested Fix

Normalize locale before array usage:

$locale = (string) ($this->_localeResolver->getLocale() ?? '');

self::$_currencyCache[$locale][$currency] = $currencyObject;

And reuse $locale consistently throughout the method.


Locale value used as array key should always be safely normalized to a string.

Actual result

PHP emits warning:

Deprecated: Using null as array offset is deprecated

Triggered during currency cache storage when locale is null or not normalized.


Additional information

No response

Release note

No response

Triage and priority

  • Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

Status
Ready for Development

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions