What is the relation between compile time execution of import/use and its scope and dynamics?

拜拜、爱过 提交于 2021-01-29 09:00:31

问题


This question originates from my previous question Why do fully qualified names have to be used when dynamically assessing namespaced elements? and another question Use php namespace inside function. Both of these questions boil down to the following explanation by php.net:

Importing is performed at compile-time, and so does not affect dynamic class, function or constant names.... ....The use keyword must be declared in the outermost scope of a file (the global scope) or inside namespace declarations. This is because the importing is done at compile time and not runtime

I am just an ex-front end developer with limited computer science background. I've got a shallow understanding of the first fact that at runtime, the machine code doesn't have the source file's namespace at hand, so dynamically resolving the variable leads to global scope, but I am not sure how this fact applies to compile time execution resulting in rendering use import available only in global scope.

Please give an exhausitive explanation of how compile time execution affects the functioning of import/use.

来源:https://stackoverflow.com/questions/60576442/what-is-the-relation-between-compile-time-execution-of-import-use-and-its-scope

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!