import like thing in php?

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
khayll
Forum Newbie
Posts: 6
Joined: Thu Jul 04, 2002 4:59 am

import like thing in php?

Post by khayll »

Hi all, I like the object oriented face of php, but can anyone tell me how I can dynamically include classes into my script ?

I mean if I have a 100 classes then I have to include them all though I am not sure which one I will really use ?

Think of FormHandler objects... I dunno which to include unless the user submits a page... and I dont want them all included...

do you have any idea ?

thx
Khayll
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

you may include php scripts at anytime,i.e.

Code: Select all

switch($_POSTї'actionType'])
{
   case 'one':
      include_once('classOne');
      $handler = new classOne;
      break;
   case 'two':
      include_once('classTwo');
      $handler = new classTwo;
      break;
   ...
   default:
      include_once('classError');
      $handler = new classError;
      break;
}
$handler->perform();
khayll
Forum Newbie
Posts: 6
Joined: Thu Jul 04, 2002 4:59 am

Post by khayll »

thankyou I didn know php can include a class in a middle of a switch case :) thats nice...
Post Reply