public function myHistory() { echo "my grand father " . parent::gfAge(); echo "my father " . parent::fAge(); //we can also use the name of class instead of 'parent' echo "my " . $this->sAge(); }
function fun2() { parent::fun1(); echo '1111111我是子类的fun2()方法<br/><br/>'; Father::fun1(); $this->fun1(); //调用自身类的fun1()方法 }
function fun1() { echo $this->username, '<br /><br />'; parent::fun1(); //当父类方法被覆盖后,要想调用父类的方法,可以用parent::方法名或Farther::方法名调用; echo '我是子类的fun()1', '<br /><br />'; Father::fun1(); }
function __construct($name) { /** * 如果创建子类时没有显示调用父类的构造方法,那么父类的构造方法不会被执行(JAVA * 中不会这样); * 但是却能执行父类的方法,在JAVA中创建一个子类会先创建其父类,那么这里可以理解为PHP类有两个构造方法; * 一个是语言层面的,一个是编译器层面的,PHP子类的创建过程中就算没有显示调用父类语言层面构造方法, * 也会自动执行编译器层面父类的构造方法。 */ //parent::__construct(); echo "construct child\n"; parent::giveChildName($this, $name); echo "my name is {$this->name}\n"; }
public function myEarning() { echo "Father told me " . parent::pocketMoney(); }
public function myHistory() { echo "my grand father " . parent::gfAge(); echo "my father " . $this->fAge(); echo "my " . $this->sAge(); }
function hello() { parent::hello(); echo '<br> Hi I\'m maulik'; }
/** * Need to test: * * 1-1-1 (OK) * 1-n-m (OK) * 1-n-1 (OK) * n-m-1 * n-m-n (OK) * n-n-1 * n-n-m */ public function xtest_add_condition_statement() { $f = new Father(); $top_conditions = 'id = 1'; $top_prefix = array('_father', ''); $father_conditions = 'name="franz"'; $father_prefix = '_father'; $result = $f->_addToConditionsStatement($top_conditions, $father_conditions, $father_prefix, $top_prefix, $f); $this->assertEqual('__owner.id = 1 AND _father.name="franz"', $result); $top_conditions = 'id = 1'; $top_prefix = array('_father', ''); $father_conditions = 'name IN ("franz","peter")'; $father_prefix = '_father'; $result = $f->_addToConditionsStatement($top_conditions, $father_conditions, $father_prefix, $top_prefix, $f); $this->assertEqual('__owner.id = 1 AND _father.name IN ("franz","peter")', $result); $top_conditions = 'id = 1'; $top_prefix = array('_father', ''); $father_conditions = 'name <> "franz"'; $father_prefix = '_father'; $result = $f->_addToConditionsStatement($top_conditions, $father_conditions, $father_prefix, $top_prefix, $f); $this->assertEqual('__owner.id = 1 AND _father.name <> "franz"', $result); $top_conditions = 'id = 1'; $top_prefix = array('_father', ''); $father_conditions = 'name < "franz"'; $father_prefix = '_father'; $result = $f->_addToConditionsStatement($top_conditions, $father_conditions, $father_prefix, $top_prefix, $f); $this->assertEqual('__owner.id = 1 AND _father.name < "franz"', $result); $top_conditions = 'id = 1'; $top_prefix = array('_father', ''); $father_conditions = 'name > "franz"'; $father_prefix = '_father'; $result = $f->_addToConditionsStatement($top_conditions, $father_conditions, $father_prefix, $top_prefix, $f); $this->assertEqual('__owner.id = 1 AND _father.name > "franz"', $result); $top_conditions = 'id = 1'; $top_prefix = array('_father', ''); $father_conditions = 'name != "franz"'; $father_prefix = '_father'; $result = $f->_addToConditionsStatement($top_conditions, $father_conditions, $father_prefix, $top_prefix, $f); $this->assertEqual('__owner.id = 1 AND _father.name != "franz"', $result); $top_conditions = 'id = 1'; $top_prefix = array('_father', ''); $father_conditions = 'name IS "franz"'; $father_prefix = '_father'; $result = $f->_addToConditionsStatement($top_conditions, $father_conditions, $father_prefix, $top_prefix, $f); $this->assertEqual('__owner.id = 1 AND _father.name IS "franz"', $result); $top_conditions = 'id = 1'; $top_prefix = array('_father', ''); $father_conditions = 'name IS NOT "franz"'; $father_prefix = '_father'; $result = $f->_addToConditionsStatement($top_conditions, $father_conditions, $father_prefix, $top_prefix, $f); $this->assertEqual('__owner.id = 1 AND _father.name IS NOT "franz"', $result); /** * bindable */ $top_conditions = 'id = ?'; $top_prefix = array('_father', ''); $father_conditions = 'name = ?'; $father_prefix = '_father'; $result = $f->_addToConditionsStatement($top_conditions, $father_conditions, $father_prefix, $top_prefix, $f); $this->assertEqual('__owner.id = ? AND _father.name = ?', $result); //die; }