Class test{
function test1()
{
echo 'inside test1';
}
function test2()
{
echo 'test2';
}
function test3()
{
echo 'test3';
}
}
$obj = new test;
$obj->test2();//prints test2
$obj->test3();//prints test3
Run Code Online (Sandbox Code Playgroud)
现在我的问题是,
如何在任何被调用的函数执行之前调用另一个函数?在上面的例子中,如何为每个其他函数调用自动调用'test1'函数,这样我就可以得到输出,
test1
test2
test1
test3
Run Code Online (Sandbox Code Playgroud)
目前我正在获得输出
test2
test3
Run Code Online (Sandbox Code Playgroud)
我不能在每个函数定义中调用'test1'函数,因为可能有很多函数.我需要一种方法来在调用类的任何函数之前自动调用函数.
任何替代方式也可以.
php ×1