Skip to content

Instantly share code, notes, and snippets.

@amashigeseiji
Created July 6, 2016 17:12
Show Gist options
  • Save amashigeseiji/2f8de4c69f01b236a80e258c7247e501 to your computer and use it in GitHub Desktop.
Save amashigeseiji/2f8de4c69f01b236a80e258c7247e501 to your computer and use it in GitHub Desktop.
<?php
class ParentClass
{
private $privateProperty = 'inParent';
public function __get($name)
{
if (property_exists(get_class($this), $name)) {
return $this->$name;
}
}
}
class Child extends ParentClass
{
private $privateProperty = 'inChild';
}
$parent = new ParentClass;
var_dump($parent->privateProperty);
$child = new Child;
var_dump($child->privateProperty);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment