只能调用一次的函数 [英] Functions that can be called only once
本文介绍了只能调用一次的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在使用以下方法:
I've been using the following approach:
$foo_called = false;
function foo()
{
if($foo_called)
{
return;
}
$foo_called = true;
// do something.
}
我一直在想是否存在更好/不同的方法.
I've been wondering if a better / different approaches existed.
推荐答案
仅出于代码清晰起见,我会执行以下操作:
Just for code clarity, I'd do something like this:
function foo()
{
static $foo_called = false;
if (!$foo_called) {
$foo_called = true;
// etc.
}
}
这篇关于只能调用一次的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文