tags:

views:

78

answers:

2

Hi I have a very simple class that implements an interface. Both the class and the interface are in the same file.

When I implement the interface I get a fatal error "Class not found", but when I remove the implements and then try to use the class I can use it fine???

Can anyone offer any advice on this?

Sorry here is some code that I am using to test at the moment:

$tester = new TypeOneTester();
$tester->test("Hello");

interface iTestInterface
{
    public function test($data);
}

class TypeOneTester implements iTestInterface
{
    public function test($data)
    {
        return $data;
    }
}
+3  A: 

Create an instance of your class after the class and the interface are defined, not before.

The order of definition in this case should be:

  1. Interface
  2. Class
  3. Instance of Class (objects)
Jacob Relkin
Why would that fail only when using interfaces though? i.e. when using normal classes and abstract classes then this issue is not present
David
+1  A: 

smells like a bug in php. Make sure it's reproducible with the latest version and post to bugs.php.net.

Reproduce code

interface I {}

$a = new A;
$b = new B;

class A {
    function __construct() { echo 'A'; }
}

class B implements I {
    function __construct() { echo 'B'; }
}

Expected

AB

Actual:

A
Fatal error: Class 'B' not found...
stereofrog