Skip to content

Instantly share code, notes, and snippets.

@Ajax30
Last active June 1, 2020 14:31
Show Gist options
  • Save Ajax30/7b15e59a1531c66383686509cbfa50c2 to your computer and use it in GitHub Desktop.
Save Ajax30/7b15e59a1531c66383686509cbfa50c2 to your computer and use it in GitHub Desktop.
<?php
Class User {
public $first_name;
public $last_name;
public $email;
public function setUserData($first_name, $last_name, $email){
$this->first_name = $first_name;
$this->last_name = $last_name;
$this->email = $email;
}
}
Class Subscriber extends User {
public $plan;
public $amount;
public function setSubscriberData($first_name, $last_name, $email, $plan, $amount){
// Get setUserData method from the parent
// in order to set values for the inherited properties
parent::setUserData($first_name, $last_name, $email);
//set values for the properties that
// are speciffic to this class
$this->plan = $plan;
$this->amount = $amount;
}
}
$bob = new User;
$carla = new Subscriber;
$bob->setUserData('Bob', 'Smith', 'bob.smith@gmail.com');
$carla->setSubscriberData('Carla', 'Smith', 'carla.smith@gmail.com', 'monthly', 10);
echo 'Full name: ' . $bob->first_name . ' ' . $bob->last_name . '<br>';
echo 'Email: ' . $bob->email . '<br>';
echo '<hr>';
echo 'Full name: ' . $carla->first_name . ' ' . $carla->last_name . '<br>';
echo 'Email: ' . $carla->email . '<br>';
echo 'Pays ' . $carla->amount . ' ' . $carla->plan . '<br>';
echo '<hr>';
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment