How can I execute a block of code exactly once in PHP?

前端 未结 3 1502
情深已故
情深已故 2020-12-30 09:29

I have one main.php file with a class definition. Other php files use this main.php file

//main.php



        
3条回答
  •  猫巷女王i
    2020-12-30 09:47

    I cannot really see how the original question relates to the accepted answer. If I want to make sure that certain code is not executed more than once by third-party scripts that include it, I just create a flag:

    
    

    The Singleton patterns just forces that all variables that instanciate one class actually point to the same only instance.

提交回复
热议问题