Closed derrabus closed 5 days ago
The instantiating part is not really needed anymore, but afair it only does that once and then clones the objects, because that was faster at the time.
looks like its still factor 10x faster:
<?php
$reflection = new ReflectionClass(stdClass::class);
$start = hrtime(true);
for ($i = 0; $i < 1000; $i++) {
$foo = $reflection->newInstanceWithoutConstructor();
}
echo hrtime(true) - $start;
echo "\n";
$start = hrtime(true);
$foo = $reflection->newInstanceWithoutConstructor();
for ($i = 0; $i < 1000; $i++) {
$bar = clone $foo;
}
echo hrtime(true) - $start;
echo "\n";
But I would be 👍 for inlinng the code into the repo to reduce reliance on mini dependencies.
The instantiating part is not really needed anymore, but afair it only does that once and then clones the objects, because that was faster at the time.
looks like its still factor 10x faster:
Thank you for clarifying. Let's keep the current logic then.
I'd like to remove
doctrine/instantiator
from our dependencies.I had a chat with @sebastianbergmann the other day and he told me how relieved he was that he could remove
doctrine/instantiator
from PHPUnit's dependencies becauseReflectionClass::newInstanceWithoutConstructor()
has become a drop-in replacement for all of his use-cases. This made me wonder if that weren't also the case for the ORM.Is there any situation where instantiator would simply call
ReflectionClass::newInstanceWithoutConstructor()
?