Cannot Redeclare 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 policies of this site About Us Learn php error cannot redeclare function more about Stack Overflow the company Business Learn more about hiring developers or posting
Php Fatal Error Cannot Redeclare
ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community
Php Fatal Error Cannot Redeclare Class Crm_core_classloader
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 “Fatal error: Cannot redeclare
Php Fatal Error Cannot Redeclare Get_avatar Url()
favorite I have a function(this is exactly how it appears, from the top of my file):
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings php fatal error cannot redeclare class createuserstable and policies of this site About Us Learn more about Stack Overflow php fatal error cannot redeclare hex2bin() the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation php fatal error cannot redeclare function previously declared 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 http://stackoverflow.com/questions/1953857/fatal-error-cannot-redeclare-function only takes a minute: Sign up Cannot redeclare the function error up vote 1 down vote favorite function getContactActiveEmails($eid) { global $db; if ($eid) { $sql = "SELECT email FROM activeEmails WHERE id = $eid"; return $db->GetCol($sql); } } I get the error "Cannot redeclare function getContactActiveEmails" The line number it gives is the last line of the function - http://stackoverflow.com/questions/5982058/cannot-redeclare-the-function-error the } All files are being called with require_once. This is the only place in the entire codebase where getContactActiveEmails is being defined. Why is this? php share|improve this question edited May 12 '11 at 17:41 foobar 2,94811943 asked May 12 '11 at 17:36 SickHippie 1,174718 Do you have functions with the same name in different files, or multiple copies of the file with this function? –KingCrunch May 12 '11 at 17:38 Maybe you're calling the function with the keyword "function" somewhere accidentally? –Chris Bornhoft May 12 '11 at 17:39 This is the only place where getContactActiveEmails is being defined. It's called in two places elsewhere. $emails = getContactActiveEmails($this->recipientID); $emails = getContactActiveEmails($eid); –SickHippie May 12 '11 at 17:40 make sure you are not using built-in type function names as your user-defined function names –mr_eclair May 12 '11 at 17:40 1 Is this function declared in some sort of loop? –Detect May 12 '11 at 17:41 | show 1 more comment 4 Answers 4 active oldest votes up vote
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: http://www.phpfreaks.com/tutorial/defining-a-php-function-only-once 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 cannot redeclare 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 error cannot redeclare 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"