Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/239.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 更严格的子接口_Php_Inheritance_Interface - Fatal编程技术网

Php 更严格的子接口

Php 更严格的子接口,php,inheritance,interface,Php,Inheritance,Interface,我有一个特殊的用例,我希望子接口在其返回值上有父接口没有的约束。例如: interface FooInterface { /** * @return mixed */ public function foo(); } interface IntegerOnlyFooInterface extends FooInterface { /** * @return integer */ public function foo();

我有一个特殊的用例,我希望子接口在其返回值上有父接口没有的约束。例如:

interface FooInterface
{
    /**
     * @return mixed
     */
    public function foo();
}

interface IntegerOnlyFooInterface extends FooInterface
{
    /**
     * @return integer
     */
    public function foo();
}
在本例中,IntegerOnlyFoo接口将仅为调用foo返回整数。因为整数也是标量,这不会破坏从FooInterface继承的契约,并且满足,因为IntegerOnlyFooInterface可以在任何需要FooInterface实例的地方使用,而不会破坏应用程序中的任何内容

不过,在某些地方,我希望强制执行整数返回值作为代码契约的一部分,因此在这些地方,我会键入integeronlyfoo接口的提示

不过,这似乎有点含糊不清,我想知道我是不是用错误的方式解决了这个问题,还是说这个问题一直在向上发展