Page 1 of 1

import like thing in php?

Posted: Thu Jul 04, 2002 4:59 am
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

Posted: Thu Jul 04, 2002 5:12 am
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();

Posted: Thu Jul 04, 2002 7:32 am
by khayll
thankyou I didn know php can include a class in a middle of a switch case :) thats nice...