Skip to content

Undefined array key "x" PHP warning #4668

@karrakoliko

Description

@karrakoliko
N tests triggered 1 PHP warning:

1) *project_root*/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Reader/Xml/Style.php:71
Undefined array key "x"

This php warning fails tests, and does not affect anything related to reading xls file.

Seems like there is an issue with the xls file itself, but "x" key is hardcoded here:

                    case 'Protection':
                        $locked = $hidden = null;
                        $styleAttributesP = $styleData->attributes($namespaces['x']); // HERE IT IS
                        if (isset($styleAttributes['Protected'])) {
                            $locked = ((bool) (string) $styleAttributes['Protected']) ? Protection::PROTECTION_PROTECTED : Protection::PROTECTION_UNPROTECTED;
                        }
                        if (isset($styleAttributesP['HideFormula'])) {
                            $hidden = ((bool) (string) $styleAttributesP['HideFormula']) ? Protection::PROTECTION_PROTECTED : Protection::PROTECTION_UNPROTECTED;
                        }

isset/array_key_exists check is missing, so php warning is triggered.

my suggestion is to add array_key_exists check to avoid reading unexisting keys from unexisting array:

$styleAttributesP = array_key_exists('x',$namespaces) ? $styleData->attributes($namespaces['x']) : [];

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