PHP code example of litert / delay-initializer

1. Go to this page and download the library: Download litert/delay-initializer 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/ */

    

litert / delay-initializer example snippets



declare (strict_types = 1);

/
class Tester implements \L\Kits\DelayInit\PropertyContainerEx
{
    use \L\Kits\DelayInit\TPropertyContainerEx;

    public function __construct()
    {
        $this->_initializeDelayInit();

        $this->setInitializer(
            'hello',
            function() {
                echo 'Initialized "hello" here.', PHP_EOL;
                return 'world';
            }
        );
    }
}

$tester = new Tester();

echo 'Now try reading the property "hello" of $tester.', PHP_EOL;

echo $tester->hello, PHP_EOL;



declare (strict_types = 1);

@property int $age
 */
class MyDI extends \L\Kits\DelayInit\PropertyDIContainer
{
}

$di = new MyDI();

$di->setInitializer(
    'name',
    function () {
        return 'Mike';
    }
);

$di->setInitializer(
    'age',
    function() {
        return 17;
    }
);

echo "Hi, I'm {$di->name}. I'm {$di->age}.", PHP_EOL;