Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Person {
- protected $name;
- public function __construct($name) {
- $this->name = $name;
- }
- public function getIntroduction() {
- return sprintf(
- 'My name is %s',
- $this->name
- );
- }
- }
- class WorkerPerson extends Person {
- protected $occupation;
- public function __construct($name, $occupation) {
- parent::__construct($name);
- $this->occupation = $occupation;
- }
- public function getIntroduction() {
- return sprintf(
- '%s and my occupation is %s',
- parent::getIntroduction(),
- $this->occupation
- );
- }
- }
- $person = new Person('Joaquin');
- echo $person->getIntroduction();
- // This prints "My name is Joaquin"
- $worker = new WorkerPerson('Joaquin', 'web development');
- echo $worker->getIntroduction();
- // This prints "My name is Joaquin and my occupation is web development"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement