Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

How implements custom php interface in zephir?

I try:

namespace Zephir;

class Test implements \AppInterface
{
    public function execute()
    {
        echo "1\n";
    }
}

And got exception:

Zephir\CompilerException: Cannot locate interface AppInterface when implementing interfaces on Zephir\Test

edited Mar '16
namespace Zephir;

interface AppInterface
{
}
namespace Zephir;

class Test implements AppInterface
{
    public function execute()
    {
        echo "1\n";
    }
}


777
edited Mar '16

This means that we can not implement custom php interfaces? Or it is necessary to duplicate the interface in the zephir?



777

I could not find the answer on the link above (

On this try again explained to the question.

I have the declared php interface and I want to implement it using zephir, is it possible?

First as I know Zephir allows only one main namespace per extension at the moment. In your example you tried to use root namespace (\\ - NS, AppInterface - class at root NS) with vendor specific namespace (Zephir). Anyway - Zephir must know about any class/function at runtime/compile time. If it is an extension - you must enable it at compile time or provide prototypes. If you want to use some prototypes you can do it as described in PR which I provided above. Thus try to imagine, how can Zephir use your interface if it doesn't know anything about it?



777

Correct me if I'm wrong. From our dialogue, I concluded: It is necessary to allocate a portion of logic and rewrite it completely and not try to obedineny php and zephir.



777
Accepted
answer

By the way I managed to get the result I needed, I created interface, class with the same namespace as in my application.

Cant you use possible extensions in config.json to allow using other namespace from other zephir directory ? Or don't ?

First as I know Zephir allows only one main namespace per extension at the moment. In your example you tried to use root namespace (\\ - NS, AppInterface - class at root NS) with vendor specific namespace (Zephir). Anyway - Zephir must know about any class/function at runtime/compile time. If it is an extension - you must enable it at compile time or provide prototypes. If you want to use some prototypes you can do it as described in PR which I provided above. Thus try to imagine, how can Zephir use your interface if it doesn't know anything about it?