什么';是Python的PHP等价物';s locals()?
我知道PHP是Python的大致等价物,但有没有等效物 我的Python:什么';是Python的PHP等价物';s locals()?,php,python,scope,Php,Python,Scope,我知道PHP是Python的大致等价物,但有没有等效物 我的Python: >>> g = 'global' >>> def test(): ... l = 'local' ... print repr(globals()); ... print repr(locals()); ... >>> >>> test() {'g': 'global', [...other stuff in the gl
>>> g = 'global'
>>> def test():
... l = 'local'
... print repr(globals());
... print repr(locals());
...
>>>
>>> test()
{'g': 'global', [...other stuff in the global scope...]}
{'l': 'local'}
我的PHP端口:
<?php
$g = 'global';
function test(){
$l = 'local';
print_r($GLOBALS);
//...please fill in the dots...:-)
}
test();
?>
Array
(
[g] => global
[...other stuff in the global scope...]
)
就是你要找的
function test(){
$a = 'local';
$b = 'another';
print_r(get_defined_vars());
}
test();
#Array
#(
# [a] => local
# [b] => another
#)
这就是你要找的
function test(){
$a = 'local';
$b = 'another';
print_r(get_defined_vars());
}
test();
#Array
#(
# [a] => local
# [b] => another
#)
很好。。他们应该在手动搜索中对此提出建议。我只有以var.Nice开头的东西。。他们应该在手动搜索中对此提出建议。我只得到了以var开头的东西。