Jump to content

Cannot redeclare function


Recommended Posts

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated