-
-
Notifications
You must be signed in to change notification settings - Fork 319
-
-
Notifications
You must be signed in to change notification settings - Fork 319
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
Error compiling factory definitions since 6.0.7 #648
Comments
Just cleaned up the example code |
mm, yeah, apparently this way of using the Let's try to reproduce it in a test and then see what the options are... |
@mnapoli guess you were right here: #605 (comment) I included the "fingerprint" of the callable in And appended a hash of the closure code: This make the tests pass, but probably more "advanced" examples can be added to the test set to reduce the risk of missing more cases? @mnapoli you can see the changes here: master...holtkamp:patch-648 @l-x can you check whether patch-branch https://github.com/holtkamp/PHP-DI/tree/patch-648 resolves the problems you had? |
First thanks alot for your extraordinary quick response! :) @holtkamp Your patch solves the initial problem but introduces a new one: <?php
declare(strict_types=1);
use DI\ContainerBuilder;
require_once __DIR__.'/../vendor/autoload.php';
$builder = new ContainerBuilder();
$builder->enableCompilation(__DIR__);
$builder->addDefinitions([
'herp' => function () { return 'derp'; }
]);
$dic = $builder->build(); If you have a look at the |
@l-x thanks for diving into this again. Pushed some more changes to https://github.com/holtkamp/PHP-DI/tree/patch-648 @mnapoli this approach does not win a price of "most elegant" code, so we might have to think of a better way to "identify" such closures |
Thanks @holtkamp for jumping on this! I'll have a look at the PR (I was away this weekend) |
@mnapoli I pushed some changes in #649 (comment), can you have a look? |
@holtkamp 👍 trying some things locally at the moment. |
The idea is that each definition is compiled into a method which bears a unique name. That unique name is a hash generated from the definition. Each definition generates its own hash, so that two different definitions have two different hashes. But it's okay if different definitions have the same hash if they are actually equal.
The idea is that each definition is compiled into a method which bears a unique name. That unique name is a hash generated from the definition. Each definition generates its own hash, so that two different definitions have two different hashes. But it's okay if different definitions have the same hash if they are actually equal.
@mnapoli I gave it a shot with the https://github.com/PHP-DI/PHP-DI/tree/fix-648 branch by using Compilation for
The PHP-DI definition is quite simple: \GuzzleHttp\Handler\CurlMultiHandler::class => \DI\autowire()->lazy(), The relevant part of the generated PHP code is: namespace ProxyManagerGeneratedProxy\__PM__\GuzzleHttp\Handler\CurlMultiHandler;
class Generated0ad1b0321b82bd00ded596ecfd75f94a extends \GuzzleHttp\Handler\CurlMultiHandler implements \ProxyManager\Proxy\VirtualProxyInterface
{
/**
* @var \Closure|null initializer responsible for generating the wrapped object
*/
private $valueHoldere7a73 = null;
/* other properties and functions */
public function __destruct()
{
$this->initializer6398d && $this->initializer6398d->__invoke($this->valueHoldere7a73, $this, '__destruct', array(), $this->initializer6398d);
return $this->valueHoldere7a73->__destruct();
} The property I am using:
Not sure whether this is a PHP-DI issue, or a ProxyManager issue? |
Oh wait I think this isn't related to #652 but because of this change: https://github.com/PHP-DI/PHP-DI/pull/645/files#diff-df30424a53a66e12594a2c5cdbe534a1R74 The idea was to "get" the proxy to force writing it to disk. But by doing that we initialize those proxies in a weird way, and the |
ah, yeah, you are right. Switched back to Currently I do not use the compiled container in big projects because of the (perceived) performance degradation as described here: #615 So I guess this is a regression introduced earlier 🤓 |
Finally I am back again ^^ Is there a patch I can test my project against? |
@l-x I suppose you can try the https://github.com/PHP-DI/PHP-DI/tree/fix-648 branch by using |
I had a chance to try the fix, unfortunately a fatal error occurs:
|
Any progress on getting this issue fixed? The v6.0.7 release has been out for almost a month with this critical issue. |
@hultberg you are welcome to help, on my side I am doing my best with the time I can find here and there. Alternatively you can support me: send me a mail (my email is on my public profile) and I can bill you (or your company) to set aside some client work and spend a day or two to work on this. That should definitely help move things faster. |
I think I've hit a big obstacle regarding the approach in #652. What #652 does is generate a unique hash per definition (the key of v6.0.7 is that such hash must be constant). The hash is based on the definition itself, and that's why #652 is such a huge refactoring. But while trying to fix #648 (comment) I noticed that sometimes the name of the definition is actually used in the code generated itself. That makes it even harder to do what was initially planned. At this point I think the safest option is to revert back to v6.0.6 (revert #605) until we find a better solution. Is there any other way to solve the original problem with Heroku? Feel free to share what you think here, unless there's any opposition to this I should be able to do that tomorrow. |
Indeed, maybe we should conclude that this whole idea for idempotent containers was a bridge too far 😨 For the time being we could:
This way a stable @mnapoli thanks for the effort you gave put into this because of my initial request, maybe someday we can tackle this challenge in the future 😄 |
👍 thanks for your efforts as well! Too bad this doesn't pays off as expected. I've planned to work on this tomorrow evening. |
I've tagged a new release with the fixes. @hultberg thank you for your support… |
@mnapoli I can confirm that this issue has been fixed with |
In
CompiledContainer.php
you'll findAs you can see the definition for
Bar
(Methodget5ffee756f39d463eb2a0c22906c0f2be
) is used for every Parameter inFuBar::__construct
.I was able to nail the issue down to
\DI\Compiler\Compiler::getHashedValue
. In this scenario the parameterstring $value
is<nested definition>Factory
for every factory definition used like above.In our case this is a crititcal issue, downgrading to 6.0.6 fixed this.
Relates to #605
The text was updated successfully, but these errors were encountered: