class a{
private $aa;
private $r;
function __construct()
{
$this->r = 'rrr';
$use = '-use';
$this->aa=function($p1 ,$p2)use($use ){
echo $this->r . $use .$p1 .$p2; //可以使用$this
};
}
function a1(){
$this->r = 'a1-';
}
function a2(){
$this->aa=function(){
echo $this->r . '-a2';
};
}
function getaa(){
return $this->aa;
}
}
$a = new a();
$f= $a->getaa(); //即使aa是public也不能直接$a->aa() 会报“Call to undefined method a::aa()”
$f('p1' ,'p2'); //rrr-usep1p2
$a->a1();
$f('pp1' ,'pp2'); //a1--usepp1pp2
$a->a2();
$f= $a->getaa();
$f(); //a1--a2