【发布时间】:2014-10-28 13:34:21
【问题描述】:
我还不了解静态和非静态方法/函数(我宁愿说方法/函数,因为我还不太清楚区别)。
我正在为我的 boxbilling (BB) 系统构建一个扩展(模块),但我有点卡住了。
这个类可以挂钩 BB 的事件并允许我执行其他操作。
class Blah_Blah
{
//The method/function that receives the event:
public static function onBeforeAdminCronRun(Box_Event $event)
{
startRun($event); //call "main" method/function to perform all my actions.
}
我正在复制 BB 使用的另一个类的编码样式。所以我最终创建了一个主函数,里面有几个嵌套函数。
public function startRun($event) // I believe that "public" exposes this method/function to the calling script, correct? if so, I can make private or remove "public"??
{
// some parameter assignments and database calls goes here.
// I will be calling the below methods/functions from here passing params where required.
$someArray = array(); // I want this array to be accessible in the methods/functions below
function firstFunction($params)
{
...some code here...
return;
}
function secondFunction()
{
...some code here...
loggingFunction('put this in log file');
return;
}
function loggingFunction($msg)
{
// code to write $msg to a file
// does not return a value
}
}
正确的调用方式是什么
startRun($event)在
public 静态函数 onBeforeAdminCronRun(Box_Event $event)内?
调用内部嵌套方法/函数的正确方法是什么
startRun($event)?
谢谢。
【问题讨论】:
标签: php