daevski Posted March 30, 2012 Report Share Posted March 30, 2012 I can't seem to get the 'email' or 'type' to correctly overwrite/apply. Anyone know why this is? I have the following code, html, and result... CLASS FILE <?php class student { public $name; public $type; protected $id; public function __construct($full_name, $their_id){ $this->name = $full_name; $this->type = 'student'; $this->id = $their_id; } protected function set_name($new_name) { $this->name = $new_name; } protected function get_name(){ return $this->name; } protected function set_type($new_type){ $this->type = $new_type; } protected function get_type(){ return $this->type; } protected function set_id($new_id){ $this->id = $new_id; } protected function get_id(){ return $this->id; } } /* additional info, inherited first from above */ class guardian extends student { protected $email; public function __contruct($full_name, $their_id, $their_email) { parent::__contruct($full_name, $their_id); // below is not working student::set_type('parent'); // below is not working either $this->email = $their_email; } protected function set_email($new_email){ $this->email = $new_email; } protected function get_email(){ return $this->email; } } VIEW PAGE <?php $stefan = new student('Stefan Mischook', 'yx54f8'); $jimmy = new guardian('Jimmy Waddles', 'xf87t2', 'onelove'); //$jimmy->set_email('jimmy.waddles@fakemail.com'); ?> <div class="person"> <p> [<?php echo $stefan->get_type();?>]<br /> Stefan's full name is: <span class="full-name"><?php echo $stefan->get_name();?></span> <br />his ID is: <span class="id"><?php echo $stefan->get_id();?></span> </p> <p> [<?php echo $jimmy->get_type();?>]<br /> Jimmy's full name is: <span class="full-name"><?php echo $jimmy->get_name();?></span> <br />his ID is: <span class="id"><?php echo $jimmy->get_id();?></span> <br />Additionally, his email address is: <span class="email"><?php echo $jimmy->get_email();?></span> </p> </div> RESULT This is the main index page [student] Stefan's full name is: Stefan Mischook his ID is: yx54f8 [student] Jimmy's full name is: Jimmy Waddles his ID is: xf87t2 Additionally, his email address is: I'm trying to learn (and extrapolate) from the OOP tutorial on killerphp! Thanks in advance! Quote Link to comment Share on other sites More sharing options...
daevski Posted March 30, 2012 Author Report Share Posted March 30, 2012 [solved] -- contruct != construct. Just a typo, otherwise the code is good Quote Link to comment Share on other sites More sharing options...
grabenair Posted March 30, 2012 Report Share Posted March 30, 2012 I hate it when I do that, look at the code for ever and then finely see something like a misspelled word. Or something like forgetting the / on a closing tag. Glad we could help you out. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.