Menu

Polylang 3.9.x fatal: 'Cannot assign null to property $locale' — root cause and the one-line fix
📰

Polylang 3.9.x fatal: 'Cannot assign null to property $locale' — root cause and the one-line fix

DEV Community: php·Roko·4 days ago
#ZtQyoNNX
#devto#dev#locale#language#polylang
Reading 0:00
15s threshold

If your site went down right after the last Polylang update with this error:

PHP Fatal error: Uncaught TypeError: Cannot assign null to property WP_Syntex\Polylang\Switcher\Element\Abstract_Element::$locale of type string in .../plugins/polylang/src/Switcher/Element/Abstract_Element.php:158

Enter fullscreen mode

Exit fullscreen mode

…then it is not your theme, and it is not a broken update in the usual sense. One language row on your site is missing its locale , and 3.9.x turned that silent bad row into a fatal.

I traced it through the 3.9.1 source. Three lines matter.

1. The typed property that fails

src/Switcher/Element/Abstract_Element.php

public string $locale ; // line 47

$this -> locale = $language -> get_locale ( 'display' ); // line 158

Enter fullscreen mode

Exit fullscreen mode

get_locale( 'display' ) returns $this->w3c ( src/language.php:608 ). If w3c is null , assigning it to a string property is a TypeError, and TypeErrors are fatal.

2.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.