8000 [var-dumper] Dump a monostate pattern internal class dumps initial class state and not actual properties · Issue #45487 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dereckson opened this issue Feb 20, 2022 · 1 comment

Comments

@dereckson
Copy link
Contributor
dereckson commented Feb 20, 2022

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

@nicolas-grekas
Copy link
Member

Thanks for the report.

nicolas-grekas added a commit that referenced this issue Feb 21, 2022
…rekas)

This PR was merged into the 4.4 branch.

Discussion
----------

[VarDumper] Fix dumping mysqli_driver instances

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #45487
| License       | MIT
| Doc PR        | -

See linked issue and https://www.php.net/manual/en/class.mysqli-driver.php

Commits
-------

88cc3af [VarDumper] Fix dumping mysqli_driver instances
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants
0