PHPDoc or type hint class as parameter to method

Viewed 2163

How can I indicate that a function/method accepts a class as a parameter? Either PHPDoc or type hinting would be sufficient, but neither seems to allow it.

Here's an example of what I'm thinking should work...

/**
 * @param $class class  A reference to a class that will be used to do something
 */
function doReallyWeirdStuff(class $class){
  $class::callStaticMethod();
}

I'm already aware of how to pass the class to this function. How do I indicate that you should do that?

2 Answers

You can't do it with PHPDoc type hinting, unless you pass an actual object instance.

You can however abuse the PHP Doc type hinting.

string|Class $class
or
Class $class

This will produce very mixed results depending on what you're running. You'll lose some of the ability to run type checking without false negatives/positives.

Related