Created
August 24, 2014 12:21
-
-
Save aik099/dfe94e42c0fb090de7e0 to your computer and use it in GitHub Desktop.
Testing private property/method inheritance in PHP
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 PrivateBase | |
{ | |
private $privateProperty = 5; | |
private function privateMethod() | |
{ | |
echo 'PrivateBase:'.$this->privateProperty; | |
} | |
public function publicBaseMethod() | |
{ | |
$this->privateMethod(); | |
} | |
} | |
class PrivateSub extends PrivateBase | |
{ | |
private $privateProperty = 10; | |
private function privateMethod() | |
{ | |
echo 'PrivateSub:'.$this->privateProperty; | |
} | |
public function publicSubMethod() | |
{ | |
$this->privateMethod(); | |
} | |
} | |
$object = new PrivateSub(); | |
$object->publicBaseMethod(); // OUTPUT: PrivateBase:5 | |
$object->publicSubMethod(); // OUTPUT: PrivateSub:10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment