PHP函数调用放置 [英] PHP Function Call Placement
本文介绍了PHP函数调用放置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请考虑以下代码段:
function f() {
return 'hi';
}
echo f();
对比此片段:
echo f();
function f() {
return 'hi';
}
当我运行脚本时,它们都产生相同的结果.太好了.
When I run the scripts, they both produce the same results. That's great.
但是我的问题是(并且在任何搜索中都找不到很好的答案或参考),在定义函数之前可以调用该函数(即,从脚本文件的顺序分析角度来看)吗?
But my question is (and I could not find a good answer or reference in any of my searches), is it okay to call the function before it is defined (ie, from a sequential parsing of the script file perspective)?
如果我将函数调用放在脚本文件中的函数定义块的前面,我不想遇到任何问题或弃用.
I don't want to run into any issues or deprecation down the road if I leave the function call ahead of the function definition block in my script file.
推荐答案
查看全文