【发布时间】:2015-09-26 16:07:54
【问题描述】:
Python 有一个函数,我们可以在其中执行另一个 python 文件并从该文件中的 vars 中获取方法。下面是解释的示例粗略代码:=
file1.py
def method1():
print 'hello world'
file2.py
globals = file1.__dict__
execfile(file1.py, globals, locals);
# locals['method1'] has method up from file1.py. One can even execute it by doing locals['method1']();
我想在 PHP 中使用类似的方法,我可以在其中读取其他 PHP 文件并获取变量中的方法。这有可能吗
【问题讨论】:
-
这有点违背php的思想,和python根本不一样。我怀疑这是直接可能的,尽管人们可能会以某种方式伪造某些东西。但我没有看到直接的解决方案。
-
这或多或少是
include所做的,除了不提供不同的范围。