Hi guys , Im fairly new to PHP OOP
I am trying to work out when is inheritance necessary ?
Example : I have 2 classes.
Now ofcourse a company will have employees so i thought this would be ok.PHP Code:<?php
class company{
public $name;
public $address;
public $email;
public $phone;
public $web;
public function cleanup($name,$address,$email,$phone,$web){
$this->name = ucfirst(mysql_real_escape_string($name));
$this->address = ucfirst(mysql_real_escape_string($address));
$this->email = mysql_real_escape_string($email);
$this->phone = mysql_real_escape_string($phone);
$this->web = mysql_real_escape_string($web);
}
private function checkemail(){
$at = stripos($this->email,"@");
if ($at == 0){
$this->error.= "Invalid Email.";
}else{
echo "Valid Email.";
}
}
private function checkphone(){
if(!is_numeric($this->phone)){
$this->error.="Invalid Phone Number.";
}
}
}
?>
Now my thinking behind this was that an employee would use all the same properties as a company but add one more being the employees position ?PHP Code:<?php
class employee extends company {
public $position;
public function setdetails($name,$address,$email,$phone,$web,$position){
}
}
?>
Is this correct ?
If so can i add the details in company and then just append the employee position to the end of the setdetails in emplyee ?
Or do both classes need to have the setdetails method?
Im not sure how i go about doing this , So if its completely wrong please tell me why and where
Kind Regards Shab







But im sure i will get there eventually lol
Bookmarks