开发者

Declaring an interface in a php file followed by a class that implements it errors

I am getting a 255 error and can not work out why

<?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";
    }
}

The output I am getting is:

开发者_如何学JAVA
1 

Process finished with exit code 255

All the code is one file. I am calling it from the command line.


If you are running this in a single file then your class needs to be declared before you instantiate it.

<?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";
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜