Create a lazy loading proxy without an extra class with ProxyManager

Code
<?php

use ProxyManager\Factory\LazyLoadingValueHolderFactory;

// a class which does a lot of expensive thing
class Foo
{
    public function 
__construct()
    {
        echo 
'<b>Foo constructor called</b>' PHP_EOL;
    }
    
    public function 
getValue()
    {
        return 
'Value of Foo' PHP_EOL;
    }
}

$factory = new LazyLoadingValueHolderFactory();

echo 
'create lazy proxy of Foo class' PHP_EOL;
$lazyproxy $factory->createProxy(Foo::CLASS,
    function (&
$wrappedObject$proxy$method$params, &$initializer) {
        
$wrappedObject = new Foo();
        
// don't initialize class again. Use same object
        
$initializer null;
    
        return 
true;
    }
);
echo 
'Foo proxy created' PHP_EOL;

echo 
$lazyproxy->getValue();
Result
create lazy proxy of Foo class
Foo proxy created
Foo constructor called
Value of Foo
Used Versions
PHP 8.2, Laminas MVC 3.2, Symfony 5.2, Laravel 8.28, PHPUnit 9.5, Doctrine ORM 2.8