Last active
December 15, 2021 14:12
-
-
Save leonardoMoliveira/f3ffa71ac4293ea03ab11e455fa92600 to your computer and use it in GitHub Desktop.
This file contains 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 | |
// Private vs Protected example code | |
class Person { | |
private string $name; | |
public function __construct(string $name) { | |
$this->name = $name; | |
} | |
protected function getName(): string | |
{ | |
return $this->name; | |
} | |
} | |
class Employ extends Person { | |
private string $room; | |
public function __construct(string $name, string $room) { | |
parent::__construct($name); | |
$this->room = $room; | |
} | |
public function getRoom(): string | |
{ | |
return $this->room; | |
} | |
public function getFullInfo(): string | |
{ | |
return "{$this->getName()}: {$this->getRoom()}"; | |
} | |
} | |
$person = new Employ('Leonardo', 'Office'); | |
print $person->getFullInfo(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment