I'm a bit puzzled here as to how come the following PHP code works:
class A
{
private function test()
{
print('test' . PHP_EOL);
}
static public function makeInstanceAndCall()
{
$test = new A();
$test->test();
}
}
A::makeInstanceAndCall();
$test = new A();
$test->test();
The last line call of the test() method obviously fails but how come calling the same method from the static context of the makeInstanceAndCall() method doesn't seem to.
Is it safe to rely on this sort of behaviour in a production environment?
And what PHP feature am I possibly missing that makes this work. I've just spent some time browsing through PHP documentation but couldn't really find a definitive answer.
Thanks.