Jump to content

daevski

New Members
  • Posts

    2
  • Joined

  • Last visited

daevski's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. [solved] -- contruct != construct. Just a typo, otherwise the code is good
  2. 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!
×
×
  • Create New...