Cannot Redeclare Function Php Error
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and php output errors policies of this site About Us Learn more about Stack Overflow the php print errors to page company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags cannot use for reading Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only
Php Show All Errors And Warnings
takes a minute: Sign up “Fatal error: Cannot redeclare here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn php cannot redeclare function previously declared more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Cannot redeclare function php up vote 14 down vote http://stackoverflow.com/questions/1953857/fatal-error-cannot-redeclare-function favorite 2 I have a function called parseDate, but when i call it on my php page (it's a joomla component page) I get Fatal error: Cannot redeclare parsedate() (previously declared in templates/ja_zeolite/assets/functions.php:2) in templates/ja_zeolite/assets/functions.php on line 21 line 2 is function parsedate($data) and line 21 is } (end of function). The function is: function parseDate($date){ $items = explode('.', $date); switch($items[1]){ case 1: $mese = 'Gen'; break; case http://stackoverflow.com/questions/10930646/cannot-redeclare-function-php 2: $mese = 'Feb'; break; case 3: $mese = 'Mar'; break; case 4: $mese = 'Apr'; break; case 5: $mese = 'Mag'; break; case 6: $mese = 'Giu'; break; case 7: $mese = 'Lug'; break; case 8: $mese = 'Ago'; break; case 9: $mese = 'Set'; break; case 10: $mese = 'Ott'; break; case 11: $mese = 'Nov'; break; case 12: $mese = 'Dic'; break; default: $mese = '---'; } $data_corretta = array(0 => $mese, 1 => $items[2]); return $data_corretta; } I also tried to change name function, but it still doesn't work. Why? php function fatal-error redeclare share|improve this question asked Jun 7 '12 at 11:11 pindol 67422237 3 Make sure you dont include the file more than once (consider using include_once or require_once) also make sure no other files define function with similar name. –skwee357 Jun 7 '12 at 11:14 2 mm.. i used include_once and it works, but I don't find where i include it other times.. –pindol Jun 7 '12 at 11:18 add a comment| 2 Answers 2 active oldest votes up vote 47 down vote accepted You (or Joomla) is likely including this file multiple times. Enclose your function in a conditional block: if (!fu connections all over the world. Join today Community Documentation Community Docs Home Develop for Drupal Theming Guide Glossary Contribute to https://www.drupal.org/node/72099 Docs Fatal error: Cannot redeclare blah_function() in ../modules/blah.module Last updated November http://www.phpfreaks.com/tutorial/defining-a-php-function-only-once 12, 2009. Created on July 4, 2006.Edited by forestmonster, kenorb, Francewhoa, kanani. Log in to edit this page.When using Drupal your browser returns the following error Fatal error: Cannot redeclare blah_function() (previously declared in /modules/blah.module:blah) in ...blah... on line blah Often occurs on: admin/modules admin/themes cannot redeclare after modifying module or theme files after duplicating module folder after upgrading the module and forgot to remove old files To fix this, select one of the possible causes listed below. Possible Cause: A function got declared inside of another function Possible Cause: Duplicate module folder Possible Cause: Duplicated PHP in block or node body Possible cannot redeclare function Cause: Module and theme use same name Possible Cause: Two functions with the same name Possible Cause: Two modules bundle the same third party library Possible Cause: you navigated to the project folder ignoring case ‹ Fatal error: Call to undefined function: form_*() on Drupal 4.7 up Possible Cause: A function got declared inside of another function › Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC. Log in or register to post comments Comments This can also be triggered by likewhoa commented December 17, 2010 at 11:38pm This can also be triggered by opcode cachers like APC and a restart of your httpd and or php-fpm is require to remedy it. Bending technology to fit business Log in or register to post comments Got Fatal error: Cannot ankheg commented November 23, 2011 at 10:02pm Got Fatal error: Cannot redeclare phptemplate_init() in /themes/engines/phptemplate/phptemplate.engine... after installing eAccelerator. Managed to solve the issue by setting eaccelerator.filter = "*.engine" in php.ini and restarting apache. This setting phpfreak here! This is for the PHP beginners out there, and possibly a refresher for those of you who are writing functions. I've ran across issues such as "Fatal error: Cannot redeclare function" in my coding history. Mostly because I was lazy and wrote the function in a template file that was called by a loop to theme content. Sometimes though, code is written on major projects where the file defining the function has to have the function in that file. Therefore, simply defining a function in your code such as: Could get you into some trouble if that file is being looped through. You'd get that "Fatal error: Cannot redeclare function" error and your code will break. So, to get around this, we simply use the built in PHP Function: function_exists() to determine if we should define this function or not. In a nutshell, you could think of the above statement like a caveman and say "IF NOT FUNCTION EXISTS foo THEN function foo..." This should help you throughout your coding troubles. I'm a bit rusty, haven't written tutorials in a few years, so let me know if you have any thoughts or if you have any recommendations on other tutorials, feel free to post something! //phpfreak http://www.phpfreaks.com Comments Michał Jarosz Feb 20, 2010 3:16:24 PM Remember that there are other functions from 'something_exists()' family, that will protect you from similar errors. class_exists() interface_exists() Eric Rosebrock Feb 20, 2010 3:49:28 PM Michal - Good call! Thanks! Brandon_R Mar 25, 2010 10:35:24 PM Hopefully namespaces will soon fix this. xeross May 6, 2010 2:07:38 PM Could you give me an example where the function/class/interface can't be in a separate included file ? That way you could get around it by using require_once/include_once. @Brandon_R: I don't think namespaces would apply in this example cadet018 Dec 8, 2010 3:21:48 AM Remember, if you are using function_exists function in "if statement" (thats where it is suppose to be anyway) then if statement should be placed before calling the actual function. Following code will give you "Fatal error: Call to undefined function foo()" because of involvement of "if statement" To avoid this, declare the function before calling it Php Error Cannot Redeclare Class
Fatal Error Cannot Redeclare Function