HEX
Server: Apache
System: Linux clpupre 5.4.0-90-generic #101-Ubuntu SMP Fri Oct 15 20:00:55 UTC 2021 x86_64
User: undanet (1000)
PHP: 7.4.3
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: //home/undanet/dump/data/PortalEmpleo/vendor/ocramius/proxy-manager/examples/ghost-object.php
<?php

declare(strict_types=1);

namespace ProxyManager\Example\GhostObject;

use Closure;
use ProxyManager\Factory\LazyLoadingGhostFactory;
use ProxyManager\Proxy\GhostObjectInterface;

require_once __DIR__ . '/../vendor/autoload.php';

class Foo
{
    private string $foo = '';

    public function __construct()
    {
        // this will be completely skipped
        sleep(5);
    }

    public function setFoo(string $foo) : void
    {
        $this->foo = $foo;
    }

    public function getFoo() : string
    {
        return $this->foo;
    }
}

(static function () : void {
    $startTime = microtime(true);
    $factory   = new LazyLoadingGhostFactory();
    $i         = 0;

    do {
        $proxy = $factory->createProxy(
            Foo::class,
            function (
                GhostObjectInterface $proxy,
                string $method,
                array $parameters,
                ?Closure & $initializer,
                array $properties
            ) : bool {
                $initializer = null;

                $properties["\0ProxyManager\\Example\\GhostObject\\Foo\0foo"] = 'Hello World!';

                return true;
            }
        );

        $i += 1;
    } while ($i < 1000);

    var_dump('time after 1000 instantiations: ' . (microtime(true) - $startTime));

    echo $proxy->getFoo() . "\n";

    var_dump('time after single call to doFoo: ' . (microtime(true) - $startTime));
})();