Jump to content

Recommended Posts

Posted

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!

Posted

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. :D

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...