最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
php中new self()关键字的用法
时间:2022-06-24 15:14:18 编辑:袖梨 来源:一聚教程网
php new self() 一般在类内部使用,作用是对自身类实例化,下面给个实例讲解如何使用:
class phpernote{
public function __construct(){
echo '一聚教程网!';
}
public static function getInstance(){
new self();
}
}
phpernote::getInstance();
返回结果:
一聚教程网!
例子
//self是指向类的本身,只跟类有关,跟任何对象实例无关
class test_self{
private static $first_count; //定义静态变量
private $last_count;
function __construct(){
$this->last_count=++self::$first_count;//直接用self调用变量的值赋值给另一个变量
}
function __destruct(){}
function print_self(){
print($this->last_count);
}
}
$abc=new test_self();//实例化对象
$abc->print_self();//1
echo '
';
总结,,self是指向当前类的指针意思就是指类的本身了,所以我们如果要调用自己的话就可以这new self来创建了
相关文章
- 污污漫画入口风险警示-合规访问指南与安全指引 12-13
- 海棠文学城网页版官网入口-2025在线网址直达 12-13
- 土豪漫画官方APP免费下载入口-正版无广告畅读保障 12-13
- 歪歪漫画app最新版下载入口-首页畅读无广告直接进 12-13
- SkrBT磁力官网最新入口-skrbt磁力引擎极速版入口 12-13
- 微博热搜网页版极速入口-微博热搜榜官方直达链接 12-13