I am curious as to why this is allowed to work, whereby you can call and successfully execute a private method on an object from outside of the object scope providing you are making the call from a class of the same type.
The private method call from a public scope to me seems not to satisfy the criteria of a private method, so why is this allowed in both PHP and Java?
<?php
class A
{
public function publicMethod ()
{
$obj = new static;
$obj->privateMethod ();
}
private function privateMethod ()
{
echo 'why does this execute?';
}
}
$obj = new A;
$obj->publicMethod ();