Description
pecl install --configureoptions="enable-apcu-debug=no" apcu crashes with a TypeError on PHP 8.5.4 with PEAR 1.10.18:
Fatal error: Uncaught TypeError: array_key_exists(): Argument #2 ($array) must be of type array, null given in /usr/local/lib/php/PEAR/Builder.php:397
This also reproduces with the -D shorthand:
pecl install -D "enable-apcu-debug=no" apcu
Environment
- PHP 8.5.4
- PEAR 1.10.18
- Docker image:
cimg/php:8.5.4
- Extension: APCu 5.1.28 (but the bug is in PEAR, not APCu)
Root cause
_parseConfigureOptions() in Builder.php (line 88) wraps the input in XML:
$data = '<XML><PROPERTIES ' . $options . ' /></XML>';
With input enable-apcu-debug=no, this produces:
<XML><PROPERTIES enable-apcu-debug=no /></XML>
This is invalid XML — attribute values must be quoted (enable-apcu-debug="no"). On PHP 8.4 and earlier, xml_parse() was lenient and parsed it anyway. On PHP 8.5, the stricter XML parser silently rejects it, so _parseConfigureOptionsStartElement() is never called, _parsed_configure_options remains null, and line 397 crashes:
if (array_key_exists($option['name'], $this->_parsed_configure_options)) {
Suggested fix
Two issues to address:
-
Quote attribute values in _parseConfigureOptions() before building the XML string, or switch to a non-XML parser for key=value pairs.
-
Null guard on line 397 — if _parsed_configure_options is null (parsing failed), fall back to the interactive prompt instead of crashing:
if (is_array($this->_parsed_configure_options) && array_key_exists($option['name'], $this->_parsed_configure_options)) {
Workaround
Pipe the answer to stdin instead:
echo "no" | pecl install apcu
Description
pecl install --configureoptions="enable-apcu-debug=no" apcucrashes with aTypeErroron PHP 8.5.4 with PEAR 1.10.18:This also reproduces with the
-Dshorthand:Environment
cimg/php:8.5.4Root cause
_parseConfigureOptions()inBuilder.php(line 88) wraps the input in XML:With input
enable-apcu-debug=no, this produces:This is invalid XML — attribute values must be quoted (
enable-apcu-debug="no"). On PHP 8.4 and earlier,xml_parse()was lenient and parsed it anyway. On PHP 8.5, the stricter XML parser silently rejects it, so_parseConfigureOptionsStartElement()is never called,_parsed_configure_optionsremainsnull, and line 397 crashes:Suggested fix
Two issues to address:
Quote attribute values in
_parseConfigureOptions()before building the XML string, or switch to a non-XML parser forkey=valuepairs.Null guard on line 397 — if
_parsed_configure_optionsis null (parsing failed), fall back to the interactive prompt instead of crashing:Workaround
Pipe the answer to stdin instead: