Archive: Namaste PHP AMQP framework v1.0 (2017-2020)
952 days continuous production uptime, 40k+ tp/s single node. Original corpo Bitbucket history not included — clean archive commit.
This commit is contained in:
41
stubs/testSingleton.php
Normal file
41
stubs/testSingleton.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
* point of this stub is to show that explicit return values have no impact in static singleton class instantiation
|
||||
*/
|
||||
class foo {
|
||||
private $bar = 0;
|
||||
private static $instance;
|
||||
|
||||
private function __construct($_which)
|
||||
{
|
||||
static::$instance = null;
|
||||
switch ($_which) {
|
||||
case 1 :
|
||||
return true;
|
||||
break;
|
||||
case 2 :
|
||||
return false;
|
||||
break;
|
||||
default :
|
||||
return null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static function getInstance($_w)
|
||||
{
|
||||
if (static::$instance === null) {
|
||||
$c = __CLASS__;
|
||||
static::$instance = new $c($_w);
|
||||
}
|
||||
return(static::$instance);
|
||||
}
|
||||
}
|
||||
|
||||
$bar = foo::getInstance(1);
|
||||
var_export($bar);
|
||||
$bar = foo::getInstance(2);
|
||||
var_export($bar);
|
||||
$bar = foo::getInstance(0);
|
||||
var_export($bar);
|
||||
|
||||
Reference in New Issue
Block a user