我们可以在PHP类中实现接口而不使用实现吗?

我们可以在PHP类中实现接口而不使用实现吗?,php,class,interface,Php,Class,Interface,我的意思是我们可以直接使用主类中的接口类作为构造函数。不,不能在PHP中实例化接口 <?php interface TestError { public function test() { print "Bye!"; // Fatal error: Interface function Test::test() cannot contain body } } interface Test { public function test(); }

我的意思是我们可以直接使用主类中的接口类作为构造函数。

不,不能在PHP中实例化接口

<?php

interface TestError {
    public function test() {
        print "Bye!"; // Fatal error: Interface function Test::test() cannot contain body
    }
}

interface Test {
    public function test();
}

class Main {
    public function __construct () {
        $test = new Test(); // Fatal error: Cannot instantiate interface
    }
}

$main = new Main();

?>


真的不知道你在问什么,但为什么不试试看它是否有效?你的意思是,比如说,
$impl=newsomeinterface{/*interface methods here*/}?PHP7已经发布。这就是你们想要的吗?你们可能在说我的意思是我们可以在PHP中将接口类实例化为null吗。TestInterface$test=null;因为PHP变量不是类型化的,所以不能这样做。您可以使用
$test=null虽然