Skip to content

Undefined array key 0 in Relation.php getForeigners() when parsing Shopware 6 product table #20190

@inventicb

Description

@inventicb

Describe the bug

Warning in ./libraries/classes/ConfigStorage/Relation.php#449
Undefined array key 0 when browsing a table with complex foreign keys
(e.g. Shopware 6 product table).

Steps to reproduce

  1. Have a Shopware 6 database on MariaDB 10.11
  2. Open phpMyAdmin and browse the product table (SELECT * FROM product)
  3. Warning appears immediately

Root cause

In Relation.php around line 449, the parser result is accessed without a null check:

// BEFORE (broken):
$stmt = $parser->statements[0];

When PhpMyAdmin\SqlParser\Parser fails to parse Shopware 6's complex
SHOW CREATE TABLE product output (due to long constraint chains and
self-referencing foreign keys), it returns an empty statements[] array.
Accessing [0] on an empty array triggers the warning.

The instanceof CreateStatement check below already guards the usage
of $stmt, but not the assignment.

Fix

// AFTER (fixed):
$stmt = $parser->statements[0] ?? null;

This is safe because the existing instanceof CreateStatement check
handles null gracefully, leaving foreign_keys_data as [].

Server configuration

  • phpMyAdmin version: 5.2.3
  • MariaDB version: 10.11.11-MariaDB-0+deb12u1 (Debian 12)
  • PHP version: PHP 8.3.6
  • Web server: nginx version: nginx/1.24.0 (Ubuntu)

Additional context

Shopware 6's product table has ~15+ foreign keys including
self-referencing ones (parent_id → id), which appear to cause the
SqlParser to return an empty statements[] instead of throwing an exception.

Verified fix works on phpMyAdmin 5.2.1 and 5.2.3.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA problem or regression with an existing featureaffects/5.2This issue or pull-request affects 5.2.x releases (and maybe further versions)affects/6.0This issue or pull-request affects 6.0.x releases (and maybe further versions)confirmed/5.2This issue is confirmed to be reproduced on 5.2 at the time this label was setpatch

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions