[SOLVED] "cannot redeclare" function even with _on

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mrchiu
Forum Newbie
Posts: 13
Joined: Sat May 28, 2005 3:33 pm

[SOLVED] "cannot redeclare" function even with _on

Post by mrchiu »

I installed php5 and functions never worked for me, so I am forced to have a copy of php4 on the side.

The first time I open the php5 page in my browser, it loads fine. When I hit refresh, it says cannot redeclare (some function)... already declared... bla bla...

I have NOT declared it anywhere else. It's a single script with a single require_once. It works fine with php4. Please advise. :x

tia
Last edited by mrchiu on Sat May 28, 2005 4:15 pm, edited 1 time in total.
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Sorry, to little info go go by. Does it do this in the ever so simple script?

Code: Select all

// index.php
<?php
 require 'foo.bar';
 hi();
?>

// foo.bar
<?php
 function hi() {
  echo 'bar';
 }
?>
Sample code?
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

what is the name of the function?

perhaps it was one added into php5???
mrchiu
Forum Newbie
Posts: 13
Joined: Sat May 28, 2005 3:33 pm

Post by mrchiu »

It still gives the error on refresh with your code.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

doh! I didn't read your post carefully enough. So it only does it on a refresh???

maybe it's some kind of cache setting:

what server type is this (os and web server)?
mrchiu
Forum Newbie
Posts: 13
Joined: Sat May 28, 2005 3:33 pm

Post by mrchiu »

I changed it to require_once('foo.php5'); but still does the same thing.
mrchiu
Forum Newbie
Posts: 13
Joined: Sat May 28, 2005 3:33 pm

Post by mrchiu »

iis6, the weird thing is that it does NOT happen with php4. :?
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

ok, so you created two files (per JAM's post) one called "foo.php" and one called "somethingelse.php" and somethingelse.php has:

Code: Select all

require_once("foo.php");
hi();
and foo.php has:

Code: Select all

function hi(){
echo "hello there";
}
and when you refresh you get an error that you can't redecalre the function?

sorry for being so mundane here, but just want to make sure we're all on the same page.

if you did indeed to all of that just like that: try using include_once() or require() or include() and see if you have the same result.

by all rights, the above should work and I don't have an explanation for you as to why it's not, first thing that comes to mind is some kind of caching issue maybe in your php.ini (espcially if it worked fine with php4.x) that leads me to believe it's not a server setting.

off the top of my head I don't knwo what it could be in php.ini that would keep a persistant copy of your function from one page refresh to the next though, I'll dig a little deeper and see if I can't find something, in the mean time try what I suggested and see if you have any better results.
mrchiu
Forum Newbie
Posts: 13
Joined: Sat May 28, 2005 3:33 pm

Post by mrchiu »

That is correct,

I have 2 files, index.php5 and foo.php5, with index require_once foo.

Here's the index.php5.
http://ns1.windermedia.net:81/test/func_test/index.php5

And here's my phpinfo

http://ns1.windermedia.net:81/test/phpinfo.php5
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

works for me...

maybe it's a browser setting?
mrchiu
Forum Newbie
Posts: 13
Joined: Sat May 28, 2005 3:33 pm

Post by mrchiu »

It was in the php.ini, accidently uncommentd php_threads.dll. Saw it when I was checking the link. oops. :oops:
mrchiu
Forum Newbie
Posts: 13
Joined: Sat May 28, 2005 3:33 pm

Post by mrchiu »

Thank you for help. Much appreciated! 8)
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

mrchiu wrote:It was in the php.ini, accidently uncommentd php_threads.dll. Saw it when I was checking the link. oops. :oops:
I belive you that it was an accident. No wonder there where issues. :lol: Glad you solved it tho.
Post Reply