【问题标题】:Declaring an interface in a php file followed by a class that implements it errors在 php 文件中声明一个接口,然后是一个实现它的类错误
【发布时间】:2011-05-26 21:49:34
【问题描述】:

我收到 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";
    }
}

我得到的输出是:

1 

Process finished with exit code 255

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

【问题讨论】:

  • 开启error_reporting。它显然已关闭并隐藏了有用的诊断信息。

标签: php command-line


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2011-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-25
    • 2012-09-22
    • 2013-07-06
    • 1970-01-01
    相关资源
    最近更新 更多