$instancePropertyName
$instancePropertyName : string
Singleton instance property name
Implements functionality allowing to reset singleton instance.
class Foo
{
use \donbidon\Lib\PHPUnit\T_ResetInstance;
protected static $myInstance;
public static function getInstance()
{
if (!is_object(self::$myInstance)) {
self::$myInstance = new self;
}
return self::$myInstance;
}
protected function __construct()
{
self::setInstancePropertyName('myInstance');
$this->allowToResetInstance();
echo sprintf("%s called%s", __METHOD__, PHP_EOL);
}
}
Foo::getInstance();
Foo::resetInstance();
Foo::getInstance();
outputs
Foo::__construct() called
Foo::__construct() called