我想防止 f( f)由除B以外的任何其他类别人员执行。 我如何检查哪类制造物体A?
<?php
class A
{
public function foo()
{
if (.... B ) // what should be on the dotts?
echo I m created by class B, which is fine ;
else
echo Execution of foo() is not allowed ;
}
}
class B
{
public function go()
{
$a = new A;
$a->foo();
}
}
class C
{
public function go()
{
$a = new A;
$a->foo();
}
}
$b = new B;
$b->go(); // result: I m created by class B, which is fine
$c = New C;
$c->go(); // result: Execution of foo() is not allowed