How can a function within a function call a variable of the parent function?
喵~
喵~ 2022-12-05 19:48:12
0
0
587
var_dump(function_exists('b')); // false
function a(){
    $var = 123;
    function b(){
        //这里怎么调用 $var 变量?
        //不能将该函数改为匿名函数
    }
}

var_dump(function_exists('b')); // false
a();
var_dump(function_exists('b')); // true 这里必须为true

Requires that function b must be in function a, and function b must be a global variable

If b is changed to an anonymous function, $var can be called, but if an anonymous function is used, how can it be upgraded to What about global functions?

喵~
喵~

reply all(0)
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template