1234567891011121314151617181920212223242526 |
- <?php
- /**
- * 多例模式
- * Created by: PhpStorm
- * User: lytian
- * Date: 2019/10/31
- * Time: 14:38
- */
- namespace app\main\InternalInterface;
- abstract class Multiton
- {
- private static $instances = [];
- public static function getInstance()
- {
- $key = get_called_class() . serialize(func_get_args());
- if (!isset(self::$instances[$key])) {
- $rc = new \ReflectionClass(get_called_class());
- self::$instances[$key] = $rc->newInstanceArgs(func_get_args());
- }
- return self::$instances[$key];
- }
- }
|