Ejemplo n.º 1
0
Archivo: test.php Proyecto: cwcw/cms
<?php

/********************************************************/
/*****                 @!!@                          ****/
/********************************************************/
/**
 *@FileName : .php
 *@Author   : WangKilin
 *@Email    : wangkilin@126.com
 *@Date     : 
 *@Homepage : http://www.yeaheasy.com
 *@Version  : 0.1
 */
class test
{
    function getInstance($cc)
    {
        echo "hello";
    }
}
if (function_exists('test::getInstance')) {
    test::getInstance();
}
if (is_callable(array('test', 'getInstance'))) {
    test::getInstance('cc');
    echo 'dddd';
}
Ejemplo n.º 2
0
    {
        static $instance2 = null;
        if ($instance2 == null) {
            $instance2 = new test('Singleton2');
        } else {
            echo "Using old class " . $instance2->myname . "\n";
        }
        return $instance2;
    }
    public function __destruct()
    {
        if (defined('SCRIPT_END')) {
            echo "Class " . $this->myname . " destroyed at script end\n";
        } else {
            echo "Class " . $this->myname . " destroyed beforce script end\n";
        }
    }
}
echo "Try static instance inside class :\n";
$getCopyofSingleton = test::getInstance();
$getCopyofSingleton = null;
$getCopyofSingleton =& test::getInstance();
$getCopyofSingleton = null;
$getCopyofSingleton = test::getInstance();
echo "Try static instance inside function :\n";
$getCopyofSingleton2 = test::getInstance2();
$getCopyofSingleton2 = null;
$getCopyofSingleton2 =& test::getInstance2();
$getCopyofSingleton2 = null;
$getCopyofSingleton2 = test::getInstance2();
define('SCRIPT_END', 1);
Ejemplo n.º 3
0
<?php

final class test
{
    private static $_INSTANCE = null;
    public static function getInstance()
    {
        if (is_null(self::$_INSTANCE)) {
            self::$_INSTANCE = new self();
        }
        return self::$_INSTANCE;
    }
    private function __construct()
    {
    }
    public final function __clone()
    {
        throw new RuntimeException('clone �֎~');
    }
}
$u = test::getInstance();
var_dump($u);