Page 1 of 1
[SOLVED] "cannot redeclare" function even with _on
Posted: Sat May 28, 2005 3:39 pm
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.
tia
Posted: Sat May 28, 2005 3:43 pm
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?
Posted: Sat May 28, 2005 3:53 pm
by Burrito
what is the name of the function?
perhaps it was one added into php5???
Posted: Sat May 28, 2005 3:54 pm
by mrchiu
It still gives the error on refresh with your code.
Posted: Sat May 28, 2005 3:57 pm
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)?
Posted: Sat May 28, 2005 3:58 pm
by mrchiu
I changed it to require_once('foo.php5'); but still does the same thing.
Posted: Sat May 28, 2005 3:59 pm
by mrchiu
iis6, the weird thing is that it does NOT happen with php4.

Posted: Sat May 28, 2005 4:05 pm
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:
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.
Posted: Sat May 28, 2005 4:11 pm
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
Posted: Sat May 28, 2005 4:14 pm
by Burrito
works for me...
maybe it's a browser setting?
Posted: Sat May 28, 2005 4:16 pm
by mrchiu
It was in the php.ini, accidently uncommentd php_threads.dll. Saw it when I was checking the link. oops.

Posted: Sat May 28, 2005 4:17 pm
by mrchiu
Thank you for help. Much appreciated!

Posted: Sat May 28, 2005 4:24 pm
by JAM
mrchiu wrote:It was in the php.ini, accidently uncommentd php_threads.dll. Saw it when I was checking the link. oops.

I belive you that it was an accident. No wonder there where issues.

Glad you solved it tho.