Skip to content

--configureoptions crashes with TypeError on PHP 8.5: array_key_exists() gets null #167

@esetnik

Description

@esetnik

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:

  1. Quote attribute values in _parseConfigureOptions() before building the XML string, or switch to a non-XML parser for key=value pairs.

  2. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions