3

I'm loading a class dynamically in PHP. This file and class name are gotten out of the database. This file must contain a class and a method. I tried to solve it with an interface, but I don't really get it how I could do it the most beautiful way.

What would be your suggestions?

2 Answers 2

5

Use class_exists() to determine if a class has been defined, method_exists() to determine if a class has a method and instanceof to determine if a class implements an interface.

Sign up to request clarification or add additional context in comments.

Comments

2

To check whether a class has been defined, use:

   if (class_exists('ClassName')) {
      // Do something
   }

To check whether a method/function exists, use:

   if (method_exists('methodName')) {
      // Do something
   }

1 Comment

You mean if a class has been defined, not instantiated. An instantiated class yields an object.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.