本文整理汇总了PHP中Foo::getInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP Foo::getInstance方法的具体用法?PHP Foo::getInstance怎么用?PHP Foo::getInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Foo
的用法示例。
在下文中一共展示了Foo::getInstance方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: bar
<?php
require_once '../odmconfig.php';
// Foo class
class Foo extends \Utility\Singleton
{
// Bar method
public function bar()
{
echo __CLASS__ . PHP_EOL;
}
}
// Returns a single instance of Foo class
$foo = Foo::getInstance();
// Prints: Foo
$foo->bar();
示例2: __destruct
public function __destruct()
{
Foo::getInstance();
}
示例3: getInstance
<?php
class Foo
{
public $foo = 1;
public function getInstance()
{
return $this;
}
}
$objFoo = new Foo();
$objFoo->getInstance()->foo = 2;
echo $objFoo->foo;
示例4: testCallStackWithTwoMiddlewares
/**
* Test call stack with two middleware
*/
public function testCallStackWithTwoMiddlewares()
{
$stack = new Mnlg\Kanda\Stack();
$stack->add('Foo', '123')->add('Foo2');
$stack->call();
$called = new \ReflectionProperty($stack, 'called');
$called->setAccessible(true);
$this->assertTrue($called->getValue($stack));
$foo = Foo::getInstance();
$foo2 = Foo2::getInstance();
$this->assertEquals($foo->param, '123');
$this->assertEquals($foo->next, $stack);
$this->assertEquals($foo2->next, $foo);
}
示例5: var_dump
{
var_dump($this);
}
}
class Foo extends Singleton
{
}
class Bar extends Singleton
{
}
class Baz extends Bar
{
}
$u = Foo::getInstance();
$v = Bar::getInstance();
$w = Baz::getInstance();
$u->identify();
$v->identify();
$w->identify();
$x = Foo::getInstance();
$y = Bar::getInstance();
$z = Baz::getInstance();
$u->identify();
$v->identify();
$w->identify();
$x->identify();
$y->identify();
$z->identify();
?>
===DONE===
示例6: getInstance
<?php
class Foo
{
public static function getInstance() : self
{
return new static();
}
}
class Bar extends Foo
{
}
var_dump(Foo::getInstance());
var_dump(Bar::getInstance());