Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

PatrickL's avatar

Interface Not Found Error in PHP

Hey, so, I am getting this error when running my PHP script.

PHP Fatal error:  Interface 'Javelin\Value\ValueInterface' not found in /Users/PatrickL/Documents/Developer/Javelin/src/Value/Value.php on line 23

It is referring to the following file.

<?php

namespace Domain;

use Javelin\Value\ValueInterface;
use Javelin\Exceptions\IllegalConversionException;

/**--------------------------------------------------------------------------
|
|   Value
|
-----------------------------------------------------------------------------
|
|   A Value represents a Value Object. A Value Object is an object that 
|   represents a descriptive aspect of a domain with no conceptual 
|   identity. Value Objects are instanciated to implement design elements
|   in which we only care about what they are. 
|
-----------------------------------------------------------------------------
*/


abstract class Value implements ValueInterface
{
    // Class definition here.
}

More specifically, line 23 is the following:

abstract class Value implements ValueInterface

For reference, ValueInterface (the interface it cannot find) looks like this.

<?php

namespace Domain; 

/**--------------------------------------------------------------------------
|
|   Value
|
-----------------------------------------------------------------------------
|
|   A Value represents a Value Object. A Value Object is an object that 
|   represents a descriptive aspect of a domain with no conceptual 
|   identity. Value Objects are instanciated to implement design elements
|   in which we only care about what they are. 
|
-----------------------------------------------------------------------------
*/


interface ValueInterface
{
    /**
    * equals() determines if the object is equal to the target
    * @param mixed
    * @return bool
    */

    public function equals($target): bool;
}

?>

And finally, directory structure looks like this:

Javelin
- src
- - Entity
- - Value
- - - Value.php
- - - ValueInterface.php
- <other files and folders>

Any idea on what the issue is? I have a feeling I am not understanding something about namespaces and automatic includes. But, what do you all think?

Thanks for the help.

0 likes
2 replies
crnkovic's avatar

You're importing ValueInterface from Javelin\Value namespace, yet the same interface is defined in Domain namespace.

PatrickL's avatar

@crnkovic Oh, so I should have used

use Javelin\Domain\ValueInterface;

instead?

How does the autoloading work with regards to namespaces and directory structure?

In a test for my ID class in the same project, it throws an error when I do

use Javelin\Utils\ID;

On a class located in src/Utils/ID/ID.php with a namespace of Utils. But, doing this instead would work just find:

use Javelin\Utils\ID\ID;

even though the namespace of the files should just be Utils. I think this might be the cause of my mix up. Lol

Thanks for the help.

Please or to participate in this conversation.