0

Is it possible to allow redeclare function which is included to main script from another .php file?

Example - my function's php file:

<?php

my_func($arg)
{
    return $arg;
}

?>

and my main php file:

<?php

for($i = 0; $i < 10; $i++)
{
    include('./functions.php');
    var_dump(my_func('test'));
}

?>

This return an error about redeclare function. I know, I can use function_exists() and include this function only once but I have 150 files with the same function's names but with another php code. I need to allow redeclare functions but how I can do it? Maybe I can clean from memory this function after included in some way?

Thanks.

Pavvcio
  • 11
  • 5
  • Does this answer your question? [Is it possible to overwrite a function in PHP](https://stackoverflow.com/questions/3620659/is-it-possible-to-overwrite-a-function-in-php) – M. Eriksson Oct 31 '21 at 09:25
  • 1
    _"but I have 150 files with the same function's names"_ - Why do you have that? That seems like a _massive_ design flaw. If the functions are different, give them different names? A function name should be descriptive of what it does. But in the example code you've posted, a quick fix would be to just include the functions file once, before the loop. – M. Eriksson Oct 31 '21 at 09:28

0 Answers0