Fatal error: Cannot redeclare date_token_list
bomarmonk - March 9, 2008 - 10:13
| Project: | Token |
| Version: | 5.x-1.10 |
| Component: | Code |
| Category: | bug report |
| Priority: | critical |
| Assigned: | greggles |
| Status: | closed |
Description
Fatal error: Cannot redeclare date_token_list() (previously declared in /home/.muckl/mysite.com/sites/all/modules/date/date/date.module:354) in /home/.muckl/mysite.com/sites/all/modules/token/token_cck.inc on line 226

#1
I should add: I get this message when submitting a CCK node with date content, or when uploading an image to the same CCK content.
#2
I saw this tonight on my site running Date 5.x-2.x-dev along with token-5.x-1.10. It has to do with the interaction between these two modules.
In the token code, at the end of token/token_cck.inc, it has this code (at the end of the file):
<?phpif (module_exists('date')) {
function date_token_list($type = 'all') {
...
?>
and in the date/date/date.module code, it has this:
<?php/**
* Callbacks for token.
*/
if (!function_exists('date_token_list')) {
function date_token_list($type = 'all') {
include_once(drupal_get_path('module', 'date') .'/date_token.inc');
return _date_token_list($type);
}
function date_token_values($type, $object = NULL, $options = array()) {
include_once(drupal_get_path('module', 'date') .'/date_token.inc');
return _date_token_values($type, $object, $options);
}
}
?>
I'm not sure what the order of module loading is, but from this code, if the date code is loaded before the token code, you'll get this error. If the token code is loaded first, the error does not occur since the date module code will check to see if the function already exists.
I'm attaching a potential diff which merely puts a "if (!function_exists('date_token_list'))" to the token code. I'm not sure if this is the right way to go overall since i haven't delved too deeply into the token or date code. I'm moving this bug to the token project since the diff is for the token code.
#3
setting code review flag
#4
The previous patch has too few parentheses. Use this one instead.
#5
I am seeing this too.
I have set up an node type with a date and a location/gmap. I get this error when trying to add a node of this type:
Fatal error: Cannot redeclare date_token_list() (previously declared in /drupal_5/sites/all/modules/date-5.x-2.0-rc/date/date/date.module:361) in /drupal_5/sites/all/modules/token-5.x-1.10/token/token_cck.inc on line 226
Thanks all for the great work as always.
--
Alan
#6
I think this is already fixed based on the work in #206649: Update Date code in Token module for API changes in Date 2.x right?
See http://cvs.drupal.org/viewvc.py/drupal/contributions/modules/token/token... which is pretty similar to what you propose.
So, upgrading to 5.x-1.x-dev should fix this. I'll mark/release a 5.x-1.11 if that version works for you folks.
Thanks for your help finding and fixing this bug. In general, if you find a bug, and especially if you are providing a patch, please do it against the latest version from the branch rather than an official snapshot release. That way you can be sure that you aren't redoing work that's already done.
#7
And that...
#8
Also noticed this when using the Workflow Module see here #238963: Cannot redeclare date_token_list()
#9
upgrading to 5.x-1.x-dev solves this issue for me.
#10
Automatically closed -- issue fixed for two weeks with no activity.