Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[var-dumper] Dump a monostate pattern internal class dumps initial class state and not actual properties #45487

Closed
@dereckson

Description

@dereckson

Symfony version(s) affected

6.0.3

Description

The mysqli_driver class implements what's documented as a monostate pattern: every instance of that class shares the same state.

As shown at mysqli_driver.c, properties are checked when they are accessed, not at object initialization.

When dumping, the clone ignores some values but more importantly, puts a 0 value for report_mode instead the actual reporting value configured.

How to reproduce

Code

$driver = new mysqli_driver();
$driver->report_mode = 3;
dump($driver);

Expected

An output similar to var_dump($driver):

^ mysqli_driver {#2663
  +client_info: mysqlnd 8.1.1
  +client_version: 80101
  +reconnect: false
  +report_mode: 3
}

Actual

^ mysqli_driver {#2663
  +reconnect: false
  +report_mode: 0
}

Possible Solution

The cloner mechanism could detect such classes with an allowlist of them (currently that list will be short: ["mysqli_driver"]) and query the properties each time they need to be accessed instead of trying to store and determine a value.

Additional Context

Initially detected in psysh: bobthecow/psysh#706

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions