Create a ghost proxy with ProxyManager

Code
<?php

use ProxyManager\Factory\LazyLoadingGhostFactory;

class 
Foo
{
    private 
$foo;
    
    public function 
__construct()
    {
        echo 
__METHOD__;
    }
    
    public function 
setFoo($foo)
    {
        
$this->foo $foo;
    }
    
    public function 
getFoo()
    {
        return 
$this->foo;
    }
}

$factory = new LazyLoadingGhostFactory();

$proxy $factory->createProxy(
    
Foo::CLASS,
    function (
$proxy$method$parameters, &$initializer) {
        
// no further instantiation
        
$initializer null;
        
$proxy->setFoo('foo');
    }
);

echo 
$proxy->getFoo();
Result
foo
Used Versions
PHP 7.1, Zend 3.0, Symfony 3.2, Laravel 5.2, PHPUnit 5.6, Doctrine 2.6