droopz17 Posted June 27, 2007 Share Posted June 27, 2007 Fatal error: Cannot redeclare encode() (previously declared DUDE, WHY THE !@#$ DOES IT DO THIS, WHATS THE POINT OF MAKING FUNCTIONS IF I CAN'T CALL THEM FROM ANOTHER FILE. I include them, and then call to them. Help me please. Link to comment https://forums.phpfreaks.com/topic/57370-fatal-error-cannot-redeclare-encode-previously-declared/ Share on other sites More sharing options...
bluebyyou Posted June 27, 2007 Share Posted June 27, 2007 Post the code please Link to comment https://forums.phpfreaks.com/topic/57370-fatal-error-cannot-redeclare-encode-previously-declared/#findComment-283752 Share on other sites More sharing options...
rhyspaterson Posted June 27, 2007 Share Posted June 27, 2007 Do the files included have a .php or .inc extension? I remember something about needing a .inc extension on included php files if you want them to be parsed. Link to comment https://forums.phpfreaks.com/topic/57370-fatal-error-cannot-redeclare-encode-previously-declared/#findComment-283753 Share on other sites More sharing options...
droopz17 Posted June 27, 2007 Author Share Posted June 27, 2007 include_once("includes/functions.php"); $test = encode('whatever'); The actual code is to encode my cookies so i rather not include it. I just need to know why any time i make a function in a seperate file then include it, if i use it more than once in my site it gives me a fatal error. Link to comment https://forums.phpfreaks.com/topic/57370-fatal-error-cannot-redeclare-encode-previously-declared/#findComment-283760 Share on other sites More sharing options...
droopz17 Posted June 27, 2007 Author Share Posted June 27, 2007 Do the files included have a .php or .inc extension? I remember something about needing a .inc extension on included php files if you want them to be parsed. .php, man i bet your right let me try it and see. Link to comment https://forums.phpfreaks.com/topic/57370-fatal-error-cannot-redeclare-encode-previously-declared/#findComment-283763 Share on other sites More sharing options...
JasonLewis Posted June 27, 2007 Share Posted June 27, 2007 that error is basically saying that you have called it once, somewhere, then in the same block of code being parsed it is being called again. i've only really seen it with classes, so paste some of the code so we can take a look. Link to comment https://forums.phpfreaks.com/topic/57370-fatal-error-cannot-redeclare-encode-previously-declared/#findComment-283767 Share on other sites More sharing options...
droopz17 Posted June 27, 2007 Author Share Posted June 27, 2007 Do the files included have a .php or .inc extension? I remember something about needing a .inc extension on included php files if you want them to be parsed. No it still is not working, please someone help me. I want my functions in a seperate file so i have it organized. I do not want to resort to putting it in my pages. Link to comment https://forums.phpfreaks.com/topic/57370-fatal-error-cannot-redeclare-encode-previously-declared/#findComment-283769 Share on other sites More sharing options...
droopz17 Posted June 27, 2007 Author Share Posted June 27, 2007 that error is basically saying that you have called it once, somewhere, then in the same block of code being parsed it is being called again. i've only really seen it with classes, so paste some of the code so we can take a look. include_once("include/encoder.inc"); $ad_encode = encode('admin_rights'); <?php function encode($var){ $out_var = ''; $s = '0'; $e = '1'; $num_char = strlen($var); //WHILE NUMBER OF CHARACTERS IS LESS THE THE NUMBER OF I while( $i < $num_char ){ $new_var = substr($var, $s, $e ); //long if statement goes here. $s++; $i++; } return $out_var; } function decode($var){ $out_var = ''; $s = '0'; $e = '2'; $num_char = strlen($var); //WHILE NUMBER OF CHARACTERS IS LESS THE THE NUMBER OF I while( $i < $num_char ){ $new_var = substr($var, $s, $e ); //long if statement goes here. $s++; $s++; $i++; $i++; } return $out_var; } ?> Link to comment https://forums.phpfreaks.com/topic/57370-fatal-error-cannot-redeclare-encode-previously-declared/#findComment-283777 Share on other sites More sharing options...
bluebyyou Posted June 27, 2007 Share Posted June 27, 2007 Are you using include_once() instead of just include() for a reason? Link to comment https://forums.phpfreaks.com/topic/57370-fatal-error-cannot-redeclare-encode-previously-declared/#findComment-283781 Share on other sites More sharing options...
mmarif4u Posted June 27, 2007 Share Posted June 27, 2007 Try this instead: require_once("include/encoder.inc"); But i am not sure about this: encoder.inc May be this will be encoder.inc.php Link to comment https://forums.phpfreaks.com/topic/57370-fatal-error-cannot-redeclare-encode-previously-declared/#findComment-283783 Share on other sites More sharing options...
droopz17 Posted June 27, 2007 Author Share Posted June 27, 2007 Are you using include_once() instead of just include() for a reason? I thought that might help, but either way it still give the fatal error, is there a way to exit from the include once you use it. kinda like when you use mysql you can close it with mysql_close Link to comment https://forums.phpfreaks.com/topic/57370-fatal-error-cannot-redeclare-encode-previously-declared/#findComment-283784 Share on other sites More sharing options...
cooldude832 Posted June 27, 2007 Share Posted June 27, 2007 check your text editor some like to add whitespace to prolouges/ other funky things take it to the old standard notepad and save in there Link to comment https://forums.phpfreaks.com/topic/57370-fatal-error-cannot-redeclare-encode-previously-declared/#findComment-283785 Share on other sites More sharing options...
JasonLewis Posted June 27, 2007 Share Posted June 27, 2007 files containing PHP must have the .php extention. kind of silly making it .inc if you just make a php file with the include and calling the encode function, does it spit out any errors? fatal errors? Link to comment https://forums.phpfreaks.com/topic/57370-fatal-error-cannot-redeclare-encode-previously-declared/#findComment-283787 Share on other sites More sharing options...
cooldude832 Posted June 27, 2007 Share Posted June 27, 2007 not true. include files can be of any extension .xasfa if you so wanted. Some people do that as a deferer of crawl bots Link to comment https://forums.phpfreaks.com/topic/57370-fatal-error-cannot-redeclare-encode-previously-declared/#findComment-283789 Share on other sites More sharing options...
droopz17 Posted June 27, 2007 Author Share Posted June 27, 2007 files containing PHP must have the .php extention. kind of silly making it .inc if you just make a php file with the include and calling the encode function, does it spit out any errors? fatal errors? Fatal error: Cannot redeclare encode() (previously declared in include/encoder.inc:2) in include/encoder.php on line 2 Link to comment https://forums.phpfreaks.com/topic/57370-fatal-error-cannot-redeclare-encode-previously-declared/#findComment-283790 Share on other sites More sharing options...
cooldude832 Posted June 27, 2007 Share Posted June 27, 2007 move your includes inside your document. The issue is your document can't handle those includes because it doesn't know your inside php NO: include_once("include/encoder.inc"); $ad_encode = encode('admin_rights'); <?php YES: <?php include_once("include/encoder.inc"); $ad_encode = encode('admin_rights'); Link to comment https://forums.phpfreaks.com/topic/57370-fatal-error-cannot-redeclare-encode-previously-declared/#findComment-283792 Share on other sites More sharing options...
mmarif4u Posted June 27, 2007 Share Posted June 27, 2007 that error is basically saying that you have called it once, somewhere, then in the same block of code being parsed it is being called again. i've only really seen it with classes, so paste some of the code so we can take a look. I am agree with ProjectFear. Did u include this file in other scripts, if so then may be there u include that file previously. Link to comment https://forums.phpfreaks.com/topic/57370-fatal-error-cannot-redeclare-encode-previously-declared/#findComment-283793 Share on other sites More sharing options...
JasonLewis Posted June 27, 2007 Share Posted June 27, 2007 but the OP said that they made a BLANK file except for the include and the calling of the function adn received an error. <?php include('includes/encoder.php'); $encode = encoder('text'); ?> OP said that that spat out errors. Link to comment https://forums.phpfreaks.com/topic/57370-fatal-error-cannot-redeclare-encode-previously-declared/#findComment-283795 Share on other sites More sharing options...
droopz17 Posted June 27, 2007 Author Share Posted June 27, 2007 My code is inside my <?php ?>, php lines. I have a site with like over a 100pages all going off a template, basically a header and footer that is included in each page i code. I have one page that request it but request the encode() fuctions like 5 times. but is only included once. Link to comment https://forums.phpfreaks.com/topic/57370-fatal-error-cannot-redeclare-encode-previously-declared/#findComment-283797 Share on other sites More sharing options...
droopz17 Posted June 27, 2007 Author Share Posted June 27, 2007 In my fuction i'm using return $out_var, Is it the return that is messing it up??? if so would using globals help? Link to comment https://forums.phpfreaks.com/topic/57370-fatal-error-cannot-redeclare-encode-previously-declared/#findComment-283799 Share on other sites More sharing options...
droopz17 Posted June 27, 2007 Author Share Posted June 27, 2007 It's all because of a bug!!! read this crap right here. http://bugs.php.net/bug.php?id=26032 Link to comment https://forums.phpfreaks.com/topic/57370-fatal-error-cannot-redeclare-encode-previously-declared/#findComment-283801 Share on other sites More sharing options...
JasonLewis Posted June 27, 2007 Share Posted June 27, 2007 that was 3 or so years ago. i am not sure thats the problem although it looks a lot like it. what version of PHP are you using? Link to comment https://forums.phpfreaks.com/topic/57370-fatal-error-cannot-redeclare-encode-previously-declared/#findComment-283802 Share on other sites More sharing options...
droopz17 Posted June 27, 2007 Author Share Posted June 27, 2007 php 5, just talked to my hosting about looking into it, but i'm just gonna put it in my files directly and be done with it, thanks to everyone that tried helping but this one is done. Link to comment https://forums.phpfreaks.com/topic/57370-fatal-error-cannot-redeclare-encode-previously-declared/#findComment-283811 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.