helmut2509 Posted March 17, 2017 Share Posted March 17, 2017 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 More sharing options...
adrian Posted March 17, 2017 Share Posted March 17, 2017 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? Link to comment Share on other sites More sharing options...
helmut2509 Posted March 17, 2017 Author Share Posted March 17, 2017 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 More sharing options...
adrian Posted March 17, 2017 Share Posted March 17, 2017 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 1 Link to comment Share on other sites More sharing options...
SamC Posted March 18, 2017 Share Posted March 18, 2017 I remember a while back another member had something like this. Not sure it's related but worth a shot. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now