Skip to content

Instantly share code, notes, and snippets.

@leonardoMoliveira
Last active December 15, 2021 14:12
Show Gist options
  • Save leonardoMoliveira/f3ffa71ac4293ea03ab11e455fa92600 to your computer and use it in GitHub Desktop.
Save leonardoMoliveira/f3ffa71ac4293ea03ab11e455fa92600 to your computer and use it in GitHub Desktop.
<?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