Skip to content

Instantly share code, notes, and snippets.

@hdvianna
Last active June 25, 2019 01:29
Show Gist options
  • Save hdvianna/2e6d3e6e5e28960fd9b7abe212011d07 to your computer and use it in GitHub Desktop.
Save hdvianna/2e6d3e6e5e28960fd9b7abe212011d07 to your computer and use it in GitHub Desktop.
<?php
class ParentClass {
private $descendant;
public function setDescendant($descendant) {
$this->descendant = $descendant;
return $this;
}
public function showDescendantValue() {
echo $this->descendant->value.PHP_EOL;
}
}
class DescendantClass extends ParentClass {
protected $value = "DescendantClass value";
}
$parentClass = new ParentClass();
$parentClass
->setDescendant(new DescendantClass())
->showDescendantValue();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment