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

Using lazy ghosts with strict-rules involves an "illegal" constructor call #263

Open
PFQNiet opened this issue Feb 21, 2025 · 2 comments
Open

Comments

@PFQNiet
Copy link

PFQNiet commented Feb 21, 2025

As a bit of a follow-up to this issue, I am using strict-rules and according to them:

Call to __construct() on an existing object is not allowed.

But it should be allowed in this specific context.

@ondrejmirtes
Copy link
Member

Please be more specific:

  1. Show a reproduction of this problem on phpstan.org/try (strict rules can be enabled there)
  2. There are four methods that accept a callable: https://wiki.php.net/rfc/lazy-objects#proposal. Is this issue related to all, or only some of them?

@PFQNiet
Copy link
Author

PFQNiet commented Feb 21, 2025

Playground demo

As far as I can tell, this will only affect ReflectionClass::newLazyGhost() specifically. Lazy Proxies are initialised by calling new Foo when the proxy is initialised, and the resetAs*() methods are themselves typically placed inside the __construct() method and will make use of some other method of the object to hydrate itself afterwards.

But newLazyGhost() requires a call to __construct() to work properly. Either that, or more reflection with $ref->getConstructor()?->invoke($obj).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants