LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-18-2006, 01:37 PM   #1
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Costa Rica
Distribution: Kubuntu, Debian, Knoppix
Posts: 2,092
Blog Entries: 1

Rep: Reputation: 90
Angry PHP4: How can I keep includes from redefinig clases?


I have a small project. I have a number of files that define different classes.

The problem is like this:

A requires B and C
B requires D
C requires D

as I'm defining a class in D, it is telling me that I can't redefine the class in file D. How can I keep this from happening?
 
Old 01-18-2006, 01:48 PM   #2
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Costa Rica
Distribution: Kubuntu, Debian, Knoppix
Posts: 2,092

Original Poster
Blog Entries: 1

Rep: Reputation: 90
To be precise:
d.php
defines class DBConection
m.php
defines class Model
s.php
includes d.php
defines class S that extends DBConection
r.php
includes s.php, m.php
defines R that extends Model
p.php
includes s.php, r.php
when I ask to run p.php (from console) I get a message that says that I can't redefine DBConnection.

Last edited by eantoranz; 01-18-2006 at 01:50 PM.
 
Old 01-18-2006, 01:48 PM   #3
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
I don't see the code, but maybe you could use another class name in D or
use require_once() instead of require() to include required files

I see your new post now
do you extends your DBConnection class in p.php ?

Last edited by keefaz; 01-18-2006 at 01:49 PM.
 
Old 01-18-2006, 02:21 PM   #4
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Costa Rica
Distribution: Kubuntu, Debian, Knoppix
Posts: 2,092

Original Poster
Blog Entries: 1

Rep: Reputation: 90
No. I don't extend it in p.php.

and now DBConnection is not extended in s.php either.... but the same problem is still there.

include_once let me advance, but then it said at some points that a class that was defined in the "included_once" file wasn't defined.

I think the problem is the "double" inclusion of s.php.

Is there a way to check for the existence of a class and if it exists, ask php to return? Maybe I can do that in the files that are going to be required more than once in a single run (like s.php, or d.php).
 
Old 01-18-2006, 03:01 PM   #5
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Costa Rica
Distribution: Kubuntu, Debian, Knoppix
Posts: 2,092

Original Poster
Blog Entries: 1

Rep: Reputation: 90
It's not elegant, but it seems to solve the problem. Where d.php starts:

Code:
if (isset($ConexionDBDefined)) {
	return(0);
}
$ConexionDBDefined = true;
 
Old 01-18-2006, 03:06 PM   #6
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Costa Rica
Distribution: Kubuntu, Debian, Knoppix
Posts: 2,092

Original Poster
Blog Entries: 1

Rep: Reputation: 90
Now it says there's one undefined class. I'll have to rethink about it... maybe php5?

I'll try later tonight.
 
Old 01-18-2006, 05:01 PM   #7
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
Replace you include with include_once. That should do the trick.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Help loading php4-gd with php4 already installed. (Debian) sdduuuude Linux - Software 3 10-24-2005 05:13 AM
getting X includes trumpetdork Linux - Software 13 05-07-2005 05:19 PM
X includes? fredws Mandriva 3 04-11-2005 09:27 PM
problemas de clases en kdevelop tranfuga Programming 2 06-16-2004 10:55 PM
Apache / PHP4 includes problem? DevlshOne Red Hat 0 01-06-2004 09:18 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:16 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration