Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
什么';是Python的PHP等价物';s locals()?_Php_Python_Scope - Fatal编程技术网

什么';是Python的PHP等价物';s locals()?

什么';是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

我知道PHP是Python的大致等价物,但有没有等效物

我的Python:

>>> 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开头的东西。