“Fatal error: Cannot redeclare

前端 未结 17 985
[愿得一人]
[愿得一人] 2020-11-22 05:26

I have a function(this is exactly how it appears, from the top of my file):



        
17条回答
  •  無奈伤痛
    2020-11-22 06:06

    I don't like function_exists('fun_name') because it relies on the function name being turned into a string, plus, you have to name it twice. Could easily break with refactoring.

    Declare your function as a lambda expression (I haven't seen this solution mentioned):

    $generate_salt = function()
    {
        ...
    };
    

    And use thusly:

    $salt = $generate_salt();
    

    Then, at re-execution of said PHP code, the function simply overwrites the previous declaration.

提交回复
热议问题