【发布时间】:2012-03-28 11:15:35
【问题描述】:
我想知道如何在“静态”类中使用 self:: 和 $this?
<?php
class Test
{
static private $inIndex = 0;
static public function getIndexPlusOne()
{
// Can I use $this-> here?
$this->raiseIndexWithOne();
return self::inIndex
}
private function raiseIndexWithOne()
{
// Can I use self:: here?
self::inIndex++;
}
}
echo Test::getIndexPlusOne();
?>
我在上面的代码中也添加了问题,但是我可以在非静态方法中使用 self:: 吗?我可以在静态方法中使用 $this-> 来调用非静态函数吗?
谢谢!
【问题讨论】:
标签: php class static this self