redecalre or cicular unit erros

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
mzfp2
Forum Contributor
Posts: 137
Joined: Mon Nov 11, 2002 9:44 am
Location: UK
Contact:

redecalre or cicular unit erros

Post by mzfp2 »

erros that look something like this

Fatal error: Cannot redeclare write() in ......../...

are extremely annoying, is there no one fix solution to resolve circular references rather than having to maze thru all the code files to see whats calling what?!

M
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

If you use include_once() or require_once() instead of include() or require() for including function or class files then you should avoid the redeclare errors because the file won't be included if it has been already.

Mac
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Post by BDKR »

Twig, as allways(!), is correct. However, this may be indicative of a greater problem. That being that there is no clear place in your projects, scripts, webpages where included or required files are placed. I like to place all files that will be included in a script that is part of say a larger website in a configuration file. If I have a need for functionality that is common only to one script or page, then I include it at the top.

Just some ideas, but if you standardized on a way of doing things it'll most likely make you a more effecient coder.

Cheers,
BDKR
mzfp2
Forum Contributor
Posts: 137
Joined: Mon Nov 11, 2002 9:44 am
Location: UK
Contact:

Post by mzfp2 »

so are you saying i shouldnt use includes? currentl my websites has its functionality divided into modules or unit files, each module may output by parsing templates, but i cam see there is a confusion as to what need whats, but im only a newbie :) !
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Post by BDKR »

mzfp2 wrote:so are you saying i shouldnt use includes?
Not at all! Like I said, just standardize how and when you include or require files. Do the same way all the time.

Cheers,
BDKR
Post Reply