Why PHP says redeclare?

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
gabrielpc1190
Forum Newbie
Posts: 5
Joined: Wed Oct 15, 2014 8:38 am

Why PHP says redeclare?

Post by gabrielpc1190 »

I have a myfunctions.php file where I am listing all the require('function1.php') that I need. Its just a function file listing.
Im trying to use a function from http://pgregg.com/projects/php/ip_in_range/ that detects if an IP is in a range.
So I copied his function and putted it on a file that then I included in myfunctions.php.

Now, I just wanted to be sure there were no errors so I opened myfunctions.php and I have this error:
[text]Fatal error: Cannot redeclare float2largearray() (previously declared in /home/www/registrocr.com/editor/workspace/syscon/functions/bitwise_float.php:19) in /home/www/registrocr.com/editor/workspace/syscon/functions/bitwise_float.php on line 27[/text]

So I went to the file and I found that line 19 is where the function is declared and line 27 is where the ending } for that function is.
The same thing happens with any of the functions on the bitwise_float.php file.

I am not redeclaring anything, I can't understand why PHP says this.

Any help would be much appreciated.
As you can notice, Im just begining with php.
sahel
Forum Newbie
Posts: 1
Joined: Wed Oct 15, 2014 9:09 am

Re: Why PHP says redeclare?

Post by sahel »

Check if your declared function page is including in the page during code running?
andy565
Forum Newbie
Posts: 7
Joined: Fri Oct 10, 2014 1:31 pm

Re: Why PHP says redeclare?

Post by andy565 »

gabrielpc1190 wrote:I have a myfunctions.php file where I am listing all the require('function1.php') that I need. Its just a function file listing.
Im trying to use a function from http://pgregg.com/projects/php/ip_in_range/ that detects if an IP is in a range.
So I copied his function and putted it on a file that then I included in myfunctions.php.

Now, I just wanted to be sure there were no errors so I opened myfunctions.php and I have this error:
[text]Fatal error: Cannot redeclare float2largearray() (previously declared in /home/www/registrocr.com/editor/workspace/syscon/functions/bitwise_float.php:19) in /home/www/registrocr.com/editor/workspace/syscon/functions/bitwise_float.php on line 27[/text]

So I went to the file and I found that line 19 is where the function is declared and line 27 is where the ending } for that function is.
The same thing happens with any of the functions on the bitwise_float.php file.

I am not redeclaring anything, I can't understand why PHP says this.

Any help would be much appreciated.
As you can notice, Im just begining with php.

Hi from what i can see is either the file you are using cannot see bitwise_float.php is it in the same folder? or that the files you have got from the site you show do not work in which case posting the files content will help us to see if it can be fixed
gabrielpc1190
Forum Newbie
Posts: 5
Joined: Wed Oct 15, 2014 8:38 am

Re: Why PHP says redeclare?

Post by gabrielpc1190 »

This is the file http://pgregg.com/projects/php/ip_in_ra ... float.phps and the http://pgregg.com/projects/php/ip_in_ra ... range2.php

My myfunctions.php content is this:

Code: Select all

<?php
include('bitwise_float.php');
include('ip_in_range2.php');
?>
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Why PHP says redeclare?

Post by Weirdan »

Your ip_in_range2.php file includes bitwise_float.php file, while you also include the latter file from your myfunctions.php file.

You may want to change your include statement to include_once (in both cases).
gabrielpc1190
Forum Newbie
Posts: 5
Joined: Wed Oct 15, 2014 8:38 am

Re: Why PHP says redeclare?

Post by gabrielpc1190 »

You are right!
I didn't saw that!.
Removed the include line and everything is perfect.
Thanks!
Post Reply