PHP code example of delights / singleton
1. Go to this page and download the library: Download delights/singleton 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/ */
delights / singleton example snippets
use \Delight\Singleton\Singleton;
class MySingleton {
use Singleton;
}
MySingleton::getInstance() // will always return the same instance
use Delight\Singleton\NotCloneable;
class SomeClass {
use NotCloneable;
}
$instance = new SomeClass();
clone $instance // throws an NonCloneableException
use Delight\Singleton\NotConstructable;
class SomeOtherClass {
use NotConstructable;
}
$someOtherClass = new SomeOtherClass(); // throws an Error, SomeOtherClass is protected