Page 1 of 1

Include issue

Posted: Mon Jul 19, 2010 11:20 pm
by weinerschizel
OK. I'm trying to include a file but having difficulties. Here's a little about what I'm writing...

File: ads.php
Description: defines a class which performs operations on sets of ads within a sql database.
Includes: ad.php

File: ad.php
Description: defines a class which contains information on a single ad and methods to manipulate that ad.

File: ad-manager.php
Description: creates a user interface to load up sets of ads and display their information in a table.
Includes: ad.php and ads.php

Here's the problem. I can only include ad.php once. Now manager.php (or ads.php depending on which one includes it) cannot find the definition of the ad class. I cannot seem to find a way around this or why php is behaving as such.

Re: Include issue

Posted: Tue Jul 20, 2010 12:56 am
by Gargoyle
you should really make a habit out of posting code + error message.

each class can only be loaded once (which is not the same as creating instances of this class).

even though it hints at bad application design that you have to include your file multiple times, here's a fix:

Code: Select all

if(!class_exists('class'))
{require('class.php');}