记录一下平常自己封装类的格式
<?php
namespace app\common\library;
class TestLibrary
{
protected static $instance;
protected $option = [];
protected $time = 0;
protected $errorMessage = '';
public function __construct()
{
$this->time = time();
}
public static function instance()
{
if (is_null(self::$instance)) {
self::$instance = new static();
}
return self::$instance;
}
protected function setError($msg)
{
$this->errorMessage = $msg;
}
public function getError()
{
return $this->errorMessage;
}
}
进行调用
use app\common\library\TestLibrary;
class Test
{
public function __construct()
{
$this->TestLib = TestLibrary::instance();
}
public function testoperate()
{
$res = $this->TestLib->xxxx();
var_dump($res);
}
}
|