The answer to this question may very well be no, and it may sound like an odd question to ask, but I have a need.
I am creating a class. This class may call another class that is optional. In the end, it will be up to the developer that uses my class to create the optional class. This optional class has some requirements. These requirements are that it has exactly two methods that can be called, that these two methods have specific names, and that each of these methods has a single parameter. What I want to do is to test to see if the class is available and meets the requirement. If it does then turn on the use of the optional class, if not then do not turn on the use of it.
I can test if the Class exists with: class_exists($className);
and I can test for each of the methods with: method_exists($className, $methodName);
Is there a way to test to see how many parameters are required by each methods? I would also need to take into account for the fact that the methods might have optional parameters, and these would not be a factor.
Any ideas are welcome.
The only thing that I can come up with so far is to read in the file for the class and use a regular expression to test the content of the file to find the methods and the number of arguments. I'd rather avoid this as I don't want the overhead of the file read each time the class in instantiated.
In the end I may simply have to go with testing to see if the methods exists and let the next developer worry about the errors if they do not create them properly, but I thought is was worth a shot to see if anyone knows another solution.