我想知道为什么php在函数内部声明一个函数时,为什么函数在类函数中声明时处理函数内声明函数的作用域。函数内声明函数的范围
例如:
function test() // global function
{
function myTest() // global function. Why?
{
print("Hello world");
}
}
class CMyTestClass
{
public function test() // method of CMyTestClass
{
function myTest() // This declaration will be global! Why?
{
print("Hello world");
}
}
}
}
任何人都可以给我讲解一下为什么出现这种情况? 谢谢你的回答。
Greetz。
为了我的好奇心,在方法中声明函数有什么好处? – 2011-01-20 13:58:30
@Gordon你必须首先调用它的函数,这样才能定义它。 – Wiseguy 2011-01-20 14:06:13
@MikeB - 也许还有其他原因,但这种做法可能是一种“匿名功能”的尝试。这样做的正确格式在这里:http://php.net/manual/en/functions.anonymous.php – rinogo 2017-06-02 20:32:32