如何在静态方法中使用非静态变量
如何在静态方法中使用非静态变量关于静态方法和静态变量:
1)static方法中不能直接使用非静态成员,因为非静态成员与实例相关,通过实例化间接使用
2)static方法中不能用this(与实例相关)
3)非static方法中可以使用static成员
如何在静态方法中使用非静态变量?实例:
<?phpclass abc{ public $count=8; function __construct(){ $this->count++; } static function getCount(){ $b=new abc(); return $b->count; }}$c=new abc();$b=new abc();echo $b->getCount();?>
页:
[1]