- var_dump: documentation ( source)
<?php
class FooSingleton extends BarSingleton
{
private $foo_instance;
public static function getInstance()
{
if (!self::$foo_instance) {
self::$foo_instance = new self;
}
}
}
class BarSingleton
{
private $bar_instance;
public static function getInstance()
{
if (!self::$bar_instance) {
// Defer to FooSingleton
self::$bar_instance = parent::getInstance();
}
}
}
$foo = FooSingleton::getInstance();
$bar = BarSingleton::getInstance();
// This should be true
var_dump($foo === $bar);