Php Cannot Redeclare Function 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
Php Fatal Error Cannot Redeclare Function Previously Declared
this site About Us Learn more about Stack Overflow the company Business Learn cannot redeclare function wordpress more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question
How To Redeclare Function In Php
x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up php allow redeclare function PHP Fatal error: Cannot redeclare function up vote 10 down vote favorite 2 I have a function A in file B.inc line 2: function A() { ... line 10: } In the apache log: PHP Fatal error: Cannot redeclare A() (previously declared in B.inc:2) in B on line 10 php apache share|improve this question asked Mar 17 '11 at 1:37 Bruce Dou 1,46762645 add fatal error cannot redeclare function previously declared in a comment| 6 Answers 6 active oldest votes up vote 14 down vote accepted I suppose you're using require "B.inc" in multiple parts? Can you try using require_once in all those instances instead? Seems like your B.inc is parsed twice. share|improve this answer answered Mar 17 '11 at 1:40 EboMike 53.2k14112133 add a comment| up vote 3 down vote I had a similar problem where a function entirely contained within a public function within a class was being reported as redeclared. I reduced the problem to class B { function __construct() { function A() { } } } $b1 = new B(); $b2 = new B(); The Fatal error: Cannot redeclare A() is produced when attempting to create $b2. The original author of the code had protected the class declaration from being redeclared with if ( !class_exists( 'B' ) ) but this does not protect the internal function A() from being redeclared if we attempt to create more than one instance of the class. Note: This is probably not the same problem as above BUT it's very similar to some of the answers in PHP Fatal error: Cann
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss
Drupal Cannot Redeclare
the workings and policies of this site About Us Learn more about drupal php fatal error: cannot redeclare Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow
Php Cannot Redeclare Class
Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each http://stackoverflow.com/questions/5333907/php-fatal-error-cannot-redeclare-function other. Join them; it only takes a minute: Sign up PHP error - cannot redeclare function up vote 6 down vote favorite 2 I have a JavaScript function making a call to a PHP script. So far so good. A problem happens when I try to do this: $hike_id = mysql_real_escape_string($_GET['hike_id']); When I import my connection file, it gives http://stackoverflow.com/questions/6309524/php-error-cannot-redeclare-function me an error that the functions in that file have already been defined and the error is this: [Fri Jun 10 12:34:43 2011] [error] [client 75.24.105.18] PHP Fatal error: Cannot redeclare hassuspicioushackerstrings() (previously declared in /home/webadmin/comehike.com/html/connect.php:16) in /home/webadmin/comehike.com/html/connect.php on line 40 The error it is referring to is a function that is in the connect script. But if I remove the include '../connect.php'; Then it will just tell me that I can not use the mysql_real_escape_string function. So I am kind of stuck between not being able to use either option. php share|improve this question edited Dec 20 '12 at 18:49 hakre 134k26216390 asked Jun 10 '11 at 16:42 Genadinik 4,93042135229 You seem to be including the file that declares hassuspicioushackerstrings(). I don't think this has to do with mysql_real_escape_string() –Pekka 웃 Jun 10 '11 at 16:45 add a comment| 5 Answers 5 active oldest votes up vote 9 down vote accepted try include_once '../connect.php'; it'll make sure you're only including once this file share|improve this answer answered Jun 10
View Latest Posts or Search: Search Answered PHP Fatal https://forums.modx.com/thread/98379/php-fatal-error-cannot-redeclare-function-previously-declared-in-a-snippet error: Cannot redeclare function() (previously declared in a snippet http://www.phpfreaks.com/tutorial/defining-a-php-function-only-once Subscribe: RSS Login to Post 128 Posts Send PM Glyn Reply #1, 1 year, 1 month ago I have written a snippet that contains a number of functions in it. When I place this snippet multiple times cannot redeclare within a template I get the following error: PHP Fatal error: Cannot redeclare displayMygif() (previously declared in ..modsnippet/25.include.cache.php:98) in ...modsnippet/25.include.cache.php on line 104 displayMygif() is a function I have created. How do I overcome this issue? Do I need to declare my functions some other way? cannot redeclare function Should I put all of my functions into a separate file and do a include_once on that. How do I do this within a snippet? Each time I call the snippet I use the following: [[!buildImage? &part=`toc` &layoutType=`[[*ImageLayout:getTVLabel]]` &imageNameStart=`is[[*IssueNumber]]-id[[*id]]-` &cog1=`[[*cog1]]` &cog2=`[[*cog2]]` &photo=`[[*photo]]` ]] cog1, cog2 and photo are image links. ImageLayout is a ToggleTVSet TV. This is all running within: I am using: MODX 2.40 Image + 2.3.4 pThumb 2.3.3 PHP 5.4.37 on a Apache server My snippet is as follows: //setup a few base variables $imagePath = 'images/icons/'; $exportPath = 'images/newsletter/'; $layout = $output = $thePart = $thelayoutType = $theImageName = $theCog1=$theCog2=$thePhoto=''; //lets get some snippet properties $thePart = $modx->getOption('part', $scriptProperties, '', true); $thelayoutType = $thePart.getLayoutName($modx->getOption('layoutType', $scriptProperties, '', true)); $theImageName = $modx->getOption('imageNameStart', $scriptProperties, '', true).$thelayoutType; $theCog1 = $imagePath.$thelayoutType.'_'.$modx->getOption('cog1', $scriptProperties, '', true).'.gif'; $theCog2 = $imagePath.$thelayoutType.'_'.$modx->getOption('cog2', $scriptProper
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"