Created
June 19, 2015 07:56
-
-
Save aleron75/8e7cd1c86287258daecf to your computer and use it in GitHub Desktop.
POC that PHP doesn't allow calling private methods from inherited context
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 MyParent | |
{ | |
public function includeFile() | |
{ | |
include "privateaccess_included.php"; | |
} | |
} | |
class MyChild extends MyParent | |
{ | |
public function publicMethod() | |
{ | |
echo "Hello public world!".PHP_EOL; | |
} | |
protected function protectedMethod() | |
{ | |
echo "Hello protected world!".PHP_EOL; | |
} | |
private function privateMethod() | |
{ | |
echo "Hello private world!".PHP_EOL; | |
} | |
} | |
$myclass = new MyChild(); | |
$myclass->includeFile(); |
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 | |
$this->publicMethod(); | |
$this->protectedMethod(); | |
$this->privateMethod(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
executing (on PHP v 5.5.22)
php -f privateaccess.php
you get the following output: