Fatal error: Cannot redeclare myFunction()

Discussion corner for Developers of Serendipity.
Post Reply
User avatar
Don Chambers
Regular
Posts: 3628
Joined: Mon Feb 13, 2006 3:40 am
Location: Chicago, IL, USA
Contact:

Fatal error: Cannot redeclare myFunction()

Post by Don Chambers » Thu Feb 12, 2015 6:28 pm

I have two different themes that have an identically names function in config.inc.php. Whenever I switch between these themes, I get this error. Is there a way to avoid this?

User avatar
garvinhicking
Core Developer
Posts: 30014
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Fatal error: Cannot redeclare myFunction()

Post by garvinhicking » Thu Feb 12, 2015 6:34 pm

Hey,

hm where exactly does the error happen, what's the exact output?

You could in your config.inc.php use a

Code: Select all

<?php 
if (!function_exists('blabla')) {
 function blabla(...)
}
to wrap a check around your function definition.

However I don't really understand in which case BOTH themes can be loaded at once, it should only always load one theme, not two...
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/

User avatar
Don Chambers
Regular
Posts: 3628
Joined: Mon Feb 13, 2006 3:40 am
Location: Chicago, IL, USA
Contact:

Re: Fatal error: Cannot redeclare myFunction()

Post by Don Chambers » Thu Feb 12, 2015 6:59 pm

Here is the scenario: Lets say I am using my theme Kinetic, and has a function named myFunction. Then I switch to a different theme named "Clean", which also has this function named myFunction. As soon as I select this second theme, I get the error:

Fatal error: Cannot redeclare myFunction() (previously declared in /var/www/vhosts/com/templates/clean/config.inc.php:11) in /var/www/vhosts/com/templates/kinetic/config.inc.php on line 33.

I can use my browser "back" button to get back to the admin page, and everything is fine from that point forward. There is no further notice or error - it only happens when I initially select a theme that has a function with the same name as the theme I just switched from. It is as if for that brief moment, both theme's configs are loaded.

Post Reply