Re: Including files within a class definition

From: Date: Mon, 05 Jul 2004 06:10:40 +0000
Subject: Re: Including files within a class definition
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-189688@lists.php.net to get a copy of this message
include (extended_methods_stuff.php); } I know that I can probably extend this class to add the extra functionality however the other generated classes rely on the name of this class so I cannot just extend this class and it's name cannot change. Is there any way to have an include prior to the class being parsed?
Are you using PHP5 yet? If so there's an answer for this: __autoload. Assuming that you held classes in files that had the same name as the class, you would use: <?php class generatedFoo { public function __autoload($class) {
    include '/path/to/class/$class.php';
} // other stuff } ?> http://www.php.net/zend-engine-2.php

« previous php.general (#189688) next »