One#
Strictly speaking, all interfaces are "listeners", listening for the interface itself to be triggered, and then performing the specified operation or processing the data passed to the interface.
The above is a summary of the plugin interface section in the Z-BlogPHP documentation: Z-BlogPHP Official Documentation;
Furthermore, the interface mechanism is essentially an application of "PHP variable functions" in PHP, where the "specified operation" is defined as a function and then called as a "variable function";
And PHP also has the concept of "variable variables", which is the basis of the Z-BlogPHP template mechanism;
"Water Hole" Z-BlogPHP Template Mechanism Explanation "Simplified Version"_Computer Network_Chén Bīng Fú Shuǐ:
[https://www.wdssmq.com/post/20201026266.html](https://www.wdssmq.com/post/20201026266.html "Water Hole" Z-BlogPHP Template Mechanism Explanation "Simplified Version"_Computer Network_Chén Bīng Fú Shuǐ")
It is the encapsulation and use of these fundamental properties that constitute Z-BlogPHP or other PHP programs, so many times what you need is to refer to the PHP documentation rather than complain that the Z-BlogPHP documentation is not detailed enough;
Two#
Illustrative code about "variable functions";
function fnTest1()
{
# code...
}
function fnTest2()
{
# code...
}
function fnTest3()
{
# code...
}
// Call different functions based on the value of $func
$func = "Test1";
// -----------
// 1. Regular if-else statement
if ($func === "Test1") {
fnTest1();
} elseif ($func === "Test2") {
fnTest2();
} elseif ($func === "Test3") {
fnTest3();
}
// -----------
// 2. Using switch case
switch ($func) {
case 'Test1':
fnTest1();
break;
case 'Test2':
fnTest2();
break;
case 'Test3':
fnTest3();
break;
default:
# code...
break;
}
// -----------
// 3. Using call_user_func
call_user_func("fn$func");
// I haven't used call_user_func much, but it's still easy to understand literally;
// I wrote it here because of the AI prompt, but the AI also told me about call_user_func_array, so I need to look up how to use it and what it's used for;
// And there's a picture about copilot in the Bilibili dynamic link below;
// -----------
// 4. Using variable functions
$func = "fn$func";
$func();
Three#
PHP: Variable Functions - Manual:
[https://www.php.net/manual/en/functions.variable-functions.php](https://www.php.net/manual/en/functions.variable-functions.php "PHP: Variable Functions - Manual")
PHP: Variable Variables - Manual:
[https://www.php.net/manual/en/language.variables.variable.php](https://www.php.net/manual/en/language.variables.variable.php "PHP: Variable Variables - Manual")
Picture about copilot - Chén Bīng Fú Shuǐ's dynamic:
[https://t.bilibili.com/708592243066273862](https://t.bilibili.com/708592243066273862 "Picture about copilot - Chén Bīng Fú Shuǐ's dynamic")