在php文件中声明一个接口,然后是一个实现它的类错误

Wil*_*ill -1 php command-line

我收到255错误,无法解决原因

<?php

print "1 \n";
$a = new myClass("a");
print "2 \n";



interface Interabc
{
    public function test($item);
}

class myClass implements Interabc
{
    public function test($item)
    {
        print "test";
    }
}
Run Code Online (Sandbox Code Playgroud)

我得到的输出是:

1 

Process finished with exit code 255
Run Code Online (Sandbox Code Playgroud)

所有代码都是一个文件.我是从命令行调用它.

Gaz*_*ler 6

如果您在单个文件中运行它,则需要在实例化之前声明您的类.

<?php   
interface Interabc
{
    public function test($item);
}

class myClass implements Interabc
{
    public function test($item)
    {
        print "test";
    }
}

print "1 \n";
$a = new myClass();
print "2 \n";
Run Code Online (Sandbox Code Playgroud)