Skip to content

Instantly share code, notes, and snippets.

@FerFuego
Created July 21, 2020 19:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FerFuego/c1ac0e35cbd9246e87f2d074a380131b to your computer and use it in GitHub Desktop.
Save FerFuego/c1ac0e35cbd9246e87f2d074a380131b to your computer and use it in GitHub Desktop.
Simple example of Abstract Class and Extends Class
<?php
abstract class Person {
protected $name;
protected $age;
public function __construct($name, $age) {
$this->name = $name;
$this->age = $age;
}
/*public function get_data() {
return 'Name' . $this->name . ' Age: ' . $this->hability;
}*/
}
class Hero extends Person {
protected $hability;
public function __construct($name, $age, $hability) {
parent::__construct($name, $age);
$this->hability = $hability;
}
public function get_data() {
return 'Name: ' . $this->name . ' Hability: ' . $this->hability . ' Age: ' . $this->age;
}
}
$hero = new Hero('Thor',30, 'GOD');
echo $hero->get_data(); // Name: Thor Hability: GOD Age: 30
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment