PHP code example of ocramius / lazy-map

1. Go to this page and download the library: Download ocramius/lazy-map library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ocramius / lazy-map example snippets


$map = new \LazyMap\CallbackLazyMap(function ($name) {
    $object = new \stdClass();

    $object->name = $name;

    return $object;
});

var_dump($map->foo);
var_dump($map->bar);
var_dump($map->{'something special'});

private function getSomething($name)
{
    if (isset($this->initialized[$name]) || array_key_exists($name, $this->initialized)) {
        return $this->initialized[$name];
    }

    return $this->initialized[$name] = new Something($name);
}