Created
July 21, 2020 19:22
-
-
Save FerFuego/c1ac0e35cbd9246e87f2d074a380131b to your computer and use it in GitHub Desktop.
Simple example of Abstract Class and Extends Class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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