Accessing a variable defined in a parent function

前端 未结 5 893
感动是毒
感动是毒 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:28

    I know this can be done with classes, however with standalone functions I was sure you could not do a retrieval without setting a public/private variable.

    But the only possible way that I can think of (not being experienced with this type of stuff) is passing $foo over to inner then doing the echo or print. :)

提交回复
热议问题