Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
<?php
class Singleton {
public static function instance() {
static $inst;
if(!isset($inst)) $inst = new static();
return $inst;
}
<?php
class Singleton {
public static function instance() {
static $inst;
if(!isset($inst)) $inst = new static();
return $inst;
}
}
class S1 extends Singleton {
}
class S2 extends Singleton {
}
$s1 = S1::instance();
print_r($s1);
$s2 = S2::instance();
print_r($s2);
S1 Object
(
)
S2 Object
(
)
<?php
class Singleton {
public static function instance() {
static $inst;
if(!isset($inst)) $inst = new static();
return $inst;
}
}
class S1 extends Singleton {
}
class S2 extends Singleton {
}
$s1 = S1::instance();
print_r($s1);
$s2 = S2::instance();
print_r($s2);
$s1->obj = true;
print_r(S1::instance());
/* Вывод:
S1 Object
(
)
S2 Object
(
)
S1 Object
(
[obj] => 1
)
*/
if (!isset(self::$instance)) {
self::$instance = new Class();
}
var game = new Game(connection);
if (isTutorial) {
var game = new Game(new MockConnection());
} else {
var game = new Game(connection);
}
Game.Connection.getInstance();
// я пишу
this.controller.connection
var image = libcanvas.getImage( 'battle-unit-enemy' );
libcanvas.addRender(function () {
this.ctx.drawImage( image, 100, 100 );
});
var image = new BigRenderer( this.scene.resources ).render();
я надеюсь бд Вы взяли лишь для примера другого синглтона, потому как он по определению не может быть синглтоном
Неужели Вы отдаете в бд сырые данные не очистив их предварительно
Request::instance()->getXssSafe('message');
Database::instance()->runQuery('query')->getXssSafe('message');
да очистка дублируется.
Синглтоны версии 5.3 в 5.2