Multipli call to a function

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
Hagar
Forum Newbie
Posts: 18
Joined: Mon May 20, 2002 3:28 am
Location: Johannesburg, South Africa

Multipli call to a function

Post by Hagar »

I get this error when I call the same function twice from a class that has an include of the class mentioned below:

Fatal error: Cannot redeclare class scripts in C:\PHP\includes\Class\Select\scripts.php on line 2
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

Yes, it pretty much tells you the error. Basically, you are including a file twice that contains a class that already exists.

Using include_once instead of include to solve this problem.
Hagar
Forum Newbie
Posts: 18
Joined: Mon May 20, 2002 3:28 am
Location: Johannesburg, South Africa

Post by Hagar »

Yes I have tried it then I get the following error:

Fatal error: Class 'scripts' not found in C:\PHP\includes\Class\Select\results.php on line 16

Because it was include before the second time you call it, it doesn't request it another time thus PHP can not re-instantiate

Code: Select all

class Script
if that makes any sense.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

if you're calling this class definition inside a function, move it outside the function.
Post Reply