IntlListFormatter object is already constructed¶
Description¶
IntlListFormatter, added in PHP 8.5, wraps ICU’s list formatter to render lists such as "a, b, and c" according to locale rules. Like other intl classes, its constructor guards against being run twice on the same object: the first successful call allocates the underlying ICU formatter, and a second call would leak that resource and leave the object in an inconsistent state.
Calling __construct() explicitly a second time – directly, or indirectly through code that re-runs construction on an already built instance – throws this error.
Example¶
<?php
$formatter = new IntlListFormatter('en_US');
// Calling the constructor a second time on the same instance
$formatter->__construct('fr_FR');
?>
Solutions¶
Create a new
IntlListFormatterinstance instead of reusing and reconstructing the same object.Never call
__construct()manually after the object has already been created withnew.
See Also¶
Changed Behavior¶
This error may appear following an evolution in behavior, in previous versions. See ` <https://php-changed-behaviors.readthedocs.io/en/latest/behavior/.html>`_.