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

前端 未结 5 667
执念已碎
执念已碎 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 19:02

    Declaring a function within another function like that would be considered bad practice in php. If you really need a function inside a() you should create a closure.

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

提交回复
热议问题