可以~但是你上面的写法有点问题。
class Lei {
function set() {
$a =2;
return $a;
}
function add(){
$lei = new Lei();
$a = $lei->set();
echo 1+$a;
}
}
$a = new Lei();
echo $a->add();
class Lei {
function set() {
$a =2;
return $a;
}
function add(){
$lei = new Lei();
$a = $lei->set();
echo 1+$a;
}
}
$a = new Lei();
echo $a->add();
class Lei
{
var $a;
function set($n)
{
$this->a = $n;
}
function show()
{
return $this->a;
}
} $lei = new Lei();
$lei->set(2);
echo $lei->show();
?>
function set() {
$this->a =2;
}
function add(){
self::set();
echo 1+$this->a;
}
}$test = new Lei();
$test->add();