Include issue

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
weinerschizel
Forum Newbie
Posts: 1
Joined: Mon Jul 19, 2010 11:13 pm

Include issue

Post 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.
Gargoyle
Forum Contributor
Posts: 130
Joined: Wed Jul 14, 2010 12:25 am

Re: Include issue

Post 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');}
Post Reply