Jump to content

Fatal Error: cannot redeclare function


Peter Troeger
 Share

Recommended Posts

Hello :)

My last problem after upgrading to PW 3 was just solves and already do I have a new one :/

My site doesn't load corrctly and I get the error

Fatal error: Cannot redeclare stripTags() (previously declared in /site/assets/cache/FileCompiler/site/templates/_functions.inc:24) in /site/templates/_functions.inc on line 32

I looks almost like it's loading the functions file twice. Once the one in my template folder and once the one in the cache folder.
I tried deleting all folder in cache und deleting wire completely and reuploading it.

I still get the same error.

Anyone any hints for me?

Thanks a lot!
Peter

Link to comment
Share on other sites

I'm only new to this too, but at a total guess:

1) Does this happen when you turn caching off and load the site?

2) Is 'stripTags()' a built in function (part of $sanitizer) and you're redefining it in your functions file?

3) Is the functions file only included once, and not somewhere else as well in another template? If '_init.php' (or whatever you've called it) is appended to your site, the functions within your '_functions.inc' file will already be available to all your other templates.

// _init.php

// Include shared functions
include_once("./_func.php"); 

4) What happens if you remove 'stripTags()' from your '_functions.inc' and then try and call this function in another template i.e. in home.php? Does the function still work?

I might be well off track but I'm sure the more experienced members will have a better idea. However, these are the avenues I'd try if you haven't already.

 
  • Like 3
Link to comment
Share on other sites

Hi Sam,

thanks for your good thoughts :)

1)  This happend after my upgrade from PW 2.7 to PW 3. I cleared the cache completely. Not sure if I can turn off the cache now. Is there some code i can add?

2)  and 4) when I delete stripTags, it just gives me an error that the next function in _functions.inc is redefined.

3) Functions is ony required_once in the init.inc. When I remove it from there I get an error because of undefined functions that can't be called

I don't understand why this worked in PW 2.7 but not in PW 3. But it kind of looks like a cache problem. But I deleted all cache files and they are rpopulated when I open the website.

Link to comment
Share on other sites

Try to disable cache for the template(s): setup > templates > cache

(at least for a temporary workaround if it's a live site)

Perhaps checking if pw namespaces are at the top of your files might be another fix (that was introduced with pw 3).

https://processwire.com/blog/posts/processwire-3.0-alpha-2-and-2.6.22-rc1/#compiled-template-files

 

  • Like 2
Link to comment
Share on other sites

I know you're going to wait awhile, but I'm only just back from work and have been thinking about this. Considering adding a namespace fixed your issue, perhaps it's also something to do with the compiler settings in:

Admin > Setup > Templates > Edit Template: "template-name")... in the 'Files' tab.

I had a different problem with this myself and had to choose 'Auto (compile when file has no namespace)'. Worth a look anyway.

  • 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...