-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Cannot assign Symfony\Component\VarDumper\Caster\CutStub to reference held by property ... #49091
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
Comments
Without a stack trace, this is not actionable. |
With this configuration, it's works but we lose the functionality of the lazy ghost object # doctrine.yaml
doctrine:
orm:
enable_lazy_ghost_objects: false |
Here's how to reproduce the error: Clone repository https://github.com/seb-jean/demo-sf Execute command: Go to: https://127.0.0.1:8000/fr Login with user : Go to: https://127.0.0.1:8000/fr/address/edit and error appears. |
Can you post the stack trace in this issue as requested ? |
|
those are log messages, not a stack trace but at least, this gives the location of the error. @nicolas-grekas shouldn't we also exclude enums (like we exclude DateTimeInterface) the DataCollector fallback caster ?
However, I still don't understand why this would assign it in the entity property. |
|
what's the password? also, which exact version of PHP do you use? |
OK, I figured out the password 😅 I don't reproduce. I think you're affected by php/php-src#8655 Please upgrade to the latest PHP 8.1 |
I have PHP 8.1.0 |
This settles it. Upgrade to 8.1.8 minimum. |
@seb-jean did you upgrade to another php version? |
Yes, now I have |
@seb-jean I have PHP 8.1.2 but I am facing the same issue on Dev... |
You have to change your version of PHP as @nicolas-grekas said. |
Ok thx |
How did that turn out, if I may ask? |
Please provide a reproducer that works on the latest version of PHP if you still experience the issue. |
It seems that only this error occurs in dev mode. |
I confirm it happened to me only in dev mode and it was solved by upgrading to PHP Version 8.1.20. On production server there is only PHP Version 8.1.2 and no problems there. |
Unfortunately it seems that Ubuntu 22.04 ships PHP 8.1 (unless we missed upgrades), which tend to exhibit this error... and the upgrade path may not be obvious to most newbees :-/ |
@olberger |
AFAIU, Ubuntu 22.04 ships only 8.1.2 + security fixes... of course one may use Ondrej's PPA, but too bad if one uses only stock Ubuntu LTS, ATM. |
Well, if you want to use a version of PHP missing 2 years of bugfixes, feel free to find a way to reimplement VarDumper without being impacted by that PHP bug (but without loosing any of the features of the component). But for that bug, it will probably be very hard (anyway, anything that has |
Actually this happen when we assign property a variable reference, very easy to reproduce: class Clazz {
public ?Clazz $parent = null;
}
$parent = new Clazz();
$s = new Clazz();
$s->parent = &$parent;
$dataCollector = new MyDataCollector();
$dataCollector->cloneVarPublic($s); // call cloneVar gives
(tested with php 8.2.16) |
Looks like the following patch would fix that issue. Could you please submit it as a bugfix on branch 5.4 with a test case derived from your reproducer? --- a/src/Symfony/Component/HttpKernel/DataCollector/DataCollector.php
+++ b/src/Symfony/Component/HttpKernel/DataCollector/DataCollector.php
@@ -61,8 +61,16 @@ abstract class DataCollector implements DataCollectorInterface
'*' => function ($v, array $a, Stub $s, $isNested) {
if (!$v instanceof Stub) {
foreach ($a as $k => $v) {
- if (\is_object($v) && !$v instanceof \DateTimeInterface && !$v instanceof Stub) {
+ if (!\is_object($v) || $v instanceof \DateTimeInterface || $v instanceof Stub) {
+ continue;
+ }
+
+ try {
+ $a[$k] = new CutStub($v);
+ } catch (\TypeError) {
+ $a[$k] = &$v;
$a[$k] = new CutStub($v);
+ unset($v);
}
}
}
|
Thanks you, this patch fix my 1st issue, another buggy use case, is on Prestashop, with Smarty. Basically, they (Smarty) use a property assigned to a reference in destruct method: class Clazz {
public $parent = null;
public function __destruct()
{
if ($this->parent !== null && !($this->parent instanceof Clazz)) {
$c = get_class($this->parent);
throw new Error("parent not instanceof Clazz but {$c}");
}
}
}
$parent = new Clazz();
$s = new Clazz();
$s->parent = &$parent;
$dataCollector = new MyDataCollector();
$dataCollector->testClone($s); Gives:
|
Please send this reproducer as a second test case on your upcoming PR and I'll have a look? |
Hello Nicolas, here the PR #54072 thanks you so much! |
… property (ebuildy) This PR was squashed before being merged into the 5.4 branch. Discussion ---------- [HttpKernel] Fix datacollector caster for reference object property | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #49091 | License | MIT As discussed on #49091: - fix story "when assigning a variable reference to a public object property" - add test for story "use object property in destruct method" (relate to PrestaShop/PrestaShop#35466 ) Unit tests FAIL "Error: KO src/Symfony/Component/HttpKernel" --> normal Commits ------- 457a3de [HttpKernel] Fix datacollector caster for reference object property
… property (ebuildy) This PR was squashed before being merged into the 5.4 branch. Discussion ---------- [HttpKernel] Fix datacollector caster for reference object property | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #49091 | License | MIT As discussed on symfony/symfony#49091: - fix story "when assigning a variable reference to a public object property" - add test for story "use object property in destruct method" (relate to PrestaShop/PrestaShop#35466 ) Unit tests FAIL "Error: KO src/Symfony/Component/HttpKernel" --> normal Commits ------- 457a3ded28 [HttpKernel] Fix datacollector caster for reference object property
Symfony version(s) affected
6.2.4
Description
I have an error
Cannot assign Symfony\Component\VarDumper\Caster\CutStub to reference held by property App\Entity\Preference::$distance of type ?App\Enum\DistanceEnum
I have a property in Entity:
How to reproduce
With
APP_ENV=dev
, I have the error.With
APP_ENV=prod
, I have no error.Possible Solution
No response
Additional Context
No response
The text was updated successfully, but these errors were encountered: