PHP code example of koriym / null-object

1. Go to this page and download the library: Download koriym/null-object 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/ */

    

koriym / null-object example snippets


interface FooInterface
{
   public function do(): void;
}

$nullObject = $this->nullObject->newInstance(FooInterface::class);
assert($nullObject instanceof FooInterface);
$nullObject->do(); // nothing's going to happen


$class = $this->nullObject->save(FooInterface::class, '/path/to/saveDirectory');
assert(new $class instanceof FooInterface);


$loader = oad_register($loader);

    "autoload-dev": {
        "files": ["./vendor/koriym/null-object/autoload.php"]
    }

$nullClass = FooInterface::class . 'Null'; // add Null suffix to the interface
$foo = new $nullClass;  // instantiate a NullObject
assert($foo instanceof FooInterface);