nested functions in php throws an exception when the outer is called more than once

前端 未结 5 706
执念已碎
执念已碎 2021-01-19 18:35

lest assume that i have the following

function a(){
  function b(){}
}
a(); //pass
a(); //error

why in the second call an exception is thr

5条回答
  •  日久生厌
    2021-01-19 18:59

    It's exactly what is says, when you call a() again it tries to redeclare b(), declare b() outside of a() and call b() from within a() like so:

    function a() {
      b();
    }
    
    function b() {}
    
    a();
    a();
    

提交回复
热议问题