oop - Return value from PHP parent method when called from child -
oop - Return value from PHP parent method when called from child -
i new php oop not sure if going right way. parent method, isregistered(), query db correctly , homecoming value ($affected_rows) when phone call method parent, "echo" value (will not homecoming it) when phone call method child, not sure if have constructed kid incorrectly. here code:
//log in social credentials if(isset($_post["fb-reg"])) { $fboptions = array( 'email' => "joe@gmail.com", 'fbid' => "678910", 'handler' => $handler); //the db connection fbregister($fboptions); } //instantiate parent , kid , results of query function fbregister($fboptions) { $a = new newuser(); $fb = new fbuser($fboptions); $fb->isregistered(); // echo $affected_rows $y = isregistered(); echo $y; // not homecoming value of $affected_rows } //parent class class newuser { public $email; public $pass; public $dbconn; public $confirm; public $message; public function __construct($options) { $this->email = $options['email']; $this->pass = $options['password']; $this->confirm = $options['confirm']; $this->dbconn = $options['handler']; $this->message = array(); } // check if user exists ==================================== public function isregistered() { $sql=("select * test email = :email"); $query = $this->dbconn->prepare($sql); $query->execute(array(':email' => $this->email)); $affected_rows = $query->rowcount(); homecoming $affected_rows; // query works not homecoming value calling function echo $affected_rows; // query result echoed calling function } } //child class class fbuser extends newuser{ public $id; public $email; public $dbconn; function __construct($fboptions) { $this->id = $fboptions['fbid']; $this->email = $fboptions['email']; $this->dbconn = $fboptions['handler']; } public function isregistered() { parent::isregistered($this->email, $this->dbconn); } }
i needed homecoming in kid method:
return parent::isregistered($this->email, $this->dbconn);
php oop parent-child parent
Comments
Post a Comment