Skip to content
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

[VarExporter] fix contravariance problem with __unserialize() in lazy proxy #57460

Merged

Conversation

nikophil
Copy link
Contributor

@nikophil nikophil commented Jun 20, 2024

Q A
Branch? 6.4
Bug fix? yes
New feature? no
Deprecations? no
Fix #57470
License MIT

LazyProxyTrait::__unserialize() has currently the following prototype: public function __unserialize(array $data): void. So, classes defining this __unserialize() method without the array type hint could not use LazyProxyTrait

Compile Error: Declaration of Symfony\Component\VarExporter\LazyProxyTrait::__unserialize(array $data): void must be compatible with Foo::__unserialize($data)

@derrabus
Copy link
Member

Not adding types will cause trouble in other scenarios. We should probably document how to use the trait in untyped codebases.

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Jun 20, 2024

Instead, we could generate the method in ProxyHelper maybe?
Something like

use LazyProxyTrait {
    __unserialize as __doUnserialize;
}

public function __unserialize($data): void { $this->__doUnserialize($data); }

@nikophil nikophil force-pushed the fix/lazy-proxy-unserialize-type-hint branch from 0f62950 to 37e6102 Compare June 20, 2024 09:03
@stof
Copy link
Member

stof commented Jun 20, 2024

wouldn't this cause issues in those other cases mentioned above ? And if no, why not updating the trait directly ?

@nikophil
Copy link
Contributor Author

Not adding types will cause trouble in other scenarios

as a curiosity, which would be these scenarios?

Instead, we could generate the method in ProxyHelper maybe?

done!

@nicolas-grekas
Copy link
Member

why not updating the trait directly ?

for correctness and also to allow child classes to add the type hint I'd say

@nikophil nikophil force-pushed the fix/lazy-proxy-unserialize-type-hint branch 4 times, most recently from 764f35b to 41ea97a Compare June 20, 2024 11:43
@nicolas-grekas
Copy link
Member

Tests are failing so there are some details to fix but this looks good to me so far, thanks.

@nikophil
Copy link
Contributor Author

yes, I saw this... any hints about the failure?
It occurs in doctrine bridge tests: variable $service here seems to be a stdClass_c562334 (hence the failure). But I have the same behavior on branch6.4 🤔

@derrabus
Copy link
Member

The PR title does not reflect the proposed change anymore though.

@nikophil nikophil changed the title [VarExporter] LazyProxyTrait::__unserialize() should not be typehinted [VarExporter] fix covariance problem with __unserialize() in lazy proxy Jun 20, 2024
@nikophil nikophil changed the title [VarExporter] fix covariance problem with __unserialize() in lazy proxy [VarExporter] fix contravariance problem with __unserialize() in lazy proxy Jun 20, 2024
@nikophil nikophil force-pushed the fix/lazy-proxy-unserialize-type-hint branch from 41ea97a to 0591cc9 Compare June 20, 2024 13:24
@nikophil nikophil force-pushed the fix/lazy-proxy-unserialize-type-hint branch 2 times, most recently from b475c47 to 59ceea9 Compare June 24, 2024 15:52
@nikophil nikophil force-pushed the fix/lazy-proxy-unserialize-type-hint branch from 59ceea9 to 6630f5e Compare June 24, 2024 15:54
@nicolas-grekas
Copy link
Member

Thank you @nikophil.

@nicolas-grekas nicolas-grekas merged commit 265aca5 into symfony:6.4 Jun 24, 2024
7 of 10 checks passed
This was referenced Jun 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants