使用类中方法的两种方式,哪一种会更好一点儿呢?
方法一:class demo { public $a; public $b; public function func1(){ if ($a) { return true; } else { return false; } } public function func2(){ echo $b; } }// 调用$demo = new demo;$demo->a = 0;if (!$demo->func1()) { $demo->b = 1; $demo->func2();}
方法二:class demo { public $a; public $b; public function func1() { if ($a) { return true; } else { return false; } } public function func2() { if (!$this->func1()) { echo $b; } }}$demo = new demo;$demo->a = 0;$demo->b = 1;$demo->func2();
请问这两种写法,哪种更好?