类用户 {
private $_var_1 = 10;
private $_var_2 = 20;
private function _preExecute() {
//do something here before executing sub-class's method
}
private function _postExecute() {
//do something here after executing sub-class's method
}
private function _anyMethod() {
echo "Hello!";
}
public function execute($action) {
$this->_preExecute();
$obj = new __CLASS__."_".$action;
$obj->execute();
$this->_postExecute();
}
}
class User_Add
{
public function execute() {
echo $this->_var1;
echo $this->_var2;
parent::_anyMethod();
}
}
$user = new User();
$user->execute("Add");
因此,正如您所看到的,我希望能够从类User_Add访问User类的变量和方法,是否可以在PHP 5.2或更高版本中使用?
答案 0 :(得分:0)