0
类用户 {如何调用类方法在类B方法中并使类B方法和参数可从类A方法中获得?
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方法,是有可能在PHP 5.2或更高版本?
你看过继承吗? – 2010-08-25 11:50:41