Created
July 6, 2016 17:12
-
-
Save amashigeseiji/2f8de4c69f01b236a80e258c7247e501 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
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