Accessing a variable defined in a parent function

前端 未结 5 878
感动是毒
感动是毒 2020-12-03 00:10

Is there a way to access $foo from within inner()?

function outer()
{
    $foo = \"...\";

    function inner()
    {
        // pr         


        
5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-03 00:34

    I do not think it is possible.

    PHP Manual has some comment around this and none of them seam to find a solution.

    http://www.php.net/manual/en/language.variables.scope.php#77693

    Another comment suggests that nested functions are not actually "nested" for real

    http://www.php.net/manual/en/language.variables.scope.php#20407

提交回复
热议问题