Jump to content

Cannot redeclare function


helmut2509
 Share

Recommended Posts

Hi,

I wrote a custom php script functions.php which I saved in a folder tslib (same level as templates).

But when I included the script and called one of its functions I got this error:

Error: Cannot redeclare getLandById() (previously declared in .../site/tslib/functions.php:16) (line 16 of .../site/tslib/functions.php)

Moreover, processwire automatically changed my inlude statement to

 include_once(\ProcessWire\wire('files')->compile('../tslib/functions.php',array('includes'=>true,'namespace'=>true,'modules'=>true,'skipIfNamespace'=>true)));

How can I fix this???


 

Link to comment
Share on other sites

2 hours ago, adrian said:

Probably just a matter of using "include_once" or "require_once" instead of "include". There are several way to prevent PW's file compiler getting involved - do you actually need it off?

I tried both of them : "include" and "include_once" but the error persisted.

I don't know how PW's file compiler works and if deactivating it would solve my problem...

Link to comment
Share on other sites

Sorry - I didn't notice that in your code example you were already using include_once - it seemed like that was the obvious reason for the issue.

You shouldn't have to turn off the file compiler to get things working - it takes care of things if you're not namespacing your template files.

There must be something that is declaring that function more than once, but if you are certain that all calls to it are using include_once, then I would start by clearing out /site/assets/cache/FileCompiler

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

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