使用自定义对象创建界面功能

Is there an oppotunity to create an interface function in PHP, where a parameter requires to be an object, but not specified, what object it has to be?

Now my code looks like this:

interface Container {
    public static function add(\Employee $element);
}

Right now I can just implement the function with a parameter, which requires an instance from "Employee". When I now implement it in a class it looks like this:

class EmployeeContainer implements Container {
    public static function add(\Employee $element) {
        $pnr = $element->getPNR();
    }
}

When I create another class, that implements Container and set the required Object for example to Trainee, the PHP compiler throws an error:

class TraineeContainer implements Container {
    public static function add(\Trainee $element) {
        $pnr = $element->getPNR();
    }
}

Fatal error: Declaration of TraineeContainer::add($element) must be compatible with Container::add(Employee $element)

Is there a way to set in the interface the required object to a custom object?

Why I want this?

Many IDE's supporting this form of instance description to suggest methods based on an object.

Custome object argument is not possible in interface but you can achieve it in other way.

create a common base class

class SomeBaseClass{

}

extend your classes

class Employee extends SomeBaseClass{

}

class Trainee extends SomeBaseClass{

}

then use SomeBaseClass as argument in your interface

interface Container {
    public static function add(SomeBaseClass $element);
}

class EmployeeContainer implements Container {
    public static function add(SomeBaseClass $element) {
        $pnr = $element->getPNR();
    }
}

class TraineeContainer implements Container {
    public static function add(SomeBaseClass $element) {
        $pnr = $element->getPNR();
    }
}

It seems you have getPNR common function so you can create an abstract class or interface and use that in your child classes.

Unfortunately not. Only way is you should check argument type inside your method:

public static function add($element) {
    if(!$element instanceof \Trainee) {
        throw new \InvalidArgumentException("your exception message");
    }

    $pnr = $element->getPNR();
}