<?php
//5.2.6
class Sample {
private function PrivateBar() {
echo 'private called<br />';
}
public static function StaticFoo() {
echo 'static called<br />';
$y = new Sample();
$y->PrivateBar();
}
}
Sample::StaticFoo();
?>
The above code will output:
"static called
private called"
Why does $y->PrivateBar(); not throw an error? It is a private function after all.
What is the object oriented design logic behind this? Is this unique to PHP, or is this standard OOP?
Because StaticFoo, though static, is still considered part of the Sample class.
This is also reproducable in C#:
With the output: