We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Zephir Interface extends other interfaces.

Hi there.

I was looking for Zephir forum or something similar, but was not able to find it, so I'm posting my question here.

I'm trying to do this:

interface CollectionInterface extends \IteratorAggregate, \Countable

but seems like Zephir does not like this,

interface CollectionInterface extends \IteratorAggregate, \Countable

===========================================^

Is this currently supported, whats the right syntax?

Thanks.



58.4k

hi you can uploade your source ?



12.1k
edited Apr '14

interface CollectionInterface extends \IteratorAggregate, \Countable {

}



58.4k
edited Apr '14

Hi

For example use L'interface IteratorAggregate

    class NormalizeChars implements \IteratorAggregate{

            public function getIterator()
            {
                var test;
                let test = [];
                return new \ArrayIterator(test);
            }
    }

For information https://github.com/phalcon/zephir/issues/124



12.1k

Hi Duy,

Thanks for your reply, but that does not solve my issue about an interface extending multiples interfaces.



58.4k

Hi

      namespace Abc;

      class NormalizeChars implements \IteratorAggregate,\Countable
      {

                public function getIterator()
                {
                    var test;
                    let test = [];
                    return new \ArrayIterator(test);
                }

                public function count()
                {
                    return 1;
                } 
      }


12.1k

Thanks again.

Here is the thing, for every time you need to implement a Collection you need to write:

implements \IteratorAggregate,\Countable

Having a CollectionInterface that implements both interfaces, gives you the ability to just wite:

class NormalizeChars implements CollectionInterface

as many times collections you want to implement, also if you want to define a new method in your interface you can add the definition to the CollectionInterface, forcing every other class that implement CollectionIterface to implement the new method.