Superdawgie Posted May 17, 2016 Share Posted May 17, 2016 Apologies if this question has been asked before. I cannot find anything in the manual regarding this. Is there a specific place I can include reusable custom functions, so they are defined only once and can be called from any custom hook or module? We have a custom provisioning module in which we created a custom function to connect to a second database. The function code is written in the module php file. When I created a custom hook that also requires this function, I redefined the same function code into the hook php file. This caused PHP Fatal error: Cannot redeclare function. The error told me the file it was previously declared in, so I was able to remove the code from the second file to get rid of the error. As I do not know the order in which custom files are parsed. I would prefer if I can define all custom reusable code in one file that is parsed before anything else. 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted May 17, 2016 Share Posted May 17, 2016 write common functions in separate file, then include in actionhook file or addon module etc use require_once() instead of require() and include_once() instead of include() this should prevent this error 0 Quote Link to comment Share on other sites More sharing options...
Superdawgie Posted May 18, 2016 Author Share Posted May 18, 2016 Cool thanks. Dont know why I didnt think of that. 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.