Just for the case the autoload thing won’t work, I wonder if it’s fine with PHP to include a class inside a method?
Example:
public method doSomething() {
include ('MyClass.php');
$foo = MyClass::doAnotherThing();
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes, you can definitely do that. In fact, that’s exactly what the auto-loading does anyway, since
__autoload()is itself a function, and you generally use it to look around for your class file to load.If you manually include your class files like that however, you’ll definitely want to use
require_once()rather thaninclude()orrequire(), otherwise you’ll get a duplicate declaration of the class.