Is there a way to enforce variable to be one of multiple types?
Something like:
class MyClass
{
public function __construct(YourClass or TheirClass $incomingObject)
{
if($incomingObject instanceof YourClass){
echo 'Im your class';
}else{
echo 'You\'re mine class';
}
}
public function helloWorld(YourClass or TheirClass or RandomClass $greetable)
{
echo 'something..';
}
}
Thanks in advance!
You should define an interface for
YourClassand then make all classes that will be passed to whatever support that interface. Then type hint to the interface instead of the class.