# Interface and abstract method

- Thread: https://externals.io/message/48316
- Original archive: https://news-web.php.net/php.internals/48316
- Started by mathieu.suen on 2010-05-18T15:12:44+00:00
- Messages: 7
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #48316 — mathieu.suen — 2010-05-18T15:12:44+00:00

URL: https://externals.io/message/48316#48316

Hi,

In the SPL there is some interface that have abstract method:

*Countable* {
/* Methods */
abstract public int count 
<http://www.php.net/manual/en/countable.count.php> ( void )
}

While some interface have "none abstract" method.

*OuterIterator* extends Iterator 
<http://www.php.net/manual/en/class.iterator.php> {
/* Methods */
public Iterator getInnerIterator 
<http://www.php.net/manual/en/outeriterator.getchildren.php> ( void )
..snip..
}

Does  "abstract" keyword have a semantic?

Thanks

--Mathieu suen

---

## #48320 — Richard Quadling — 2010-05-18T15:50:51+00:00

URL: https://externals.io/message/48316#48320 · In reply to: #48316

> Hi,
>
> In the SPL there is some interface that have abstract method:
>
> *Countable* {
> /* Methods */
> abstract public int count <http://www.php.net/manual/en/countable.count.php>
> ( void )
> }
>
> While some interface have "none abstract" method.
>
> *OuterIterator* extends Iterator
> <http://www.php.net/manual/en/class.iterator.php> {
> /* Methods */
> public Iterator getInnerIterator
> <http://www.php.net/manual/en/outeriterator.getchildren.php> ( void )
> ..snip..
> }
>
> Does  "abstract" keyword have a semantic?
>
> Thanks
>
> --Mathieu suen
>
>
>
>

http://docs.php.net/abstract

By the nature of the method being in an interface, it is automatically
abstract - there is no code behind the method in an interface. So you
must supply the code in any class that implements the interface.
Unless the sub-class is declared as an abstract class ...

<?php
abstract class counter implements countable {
}

class counting extends counter {
  public function `count()` {
    return 1;
  }
}

$a = new counting();
echo $a->count();
?>




-- 
-----
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling

---

## #48321 — Tjerk Anne Meesters — 2010-05-18T15:55:26+00:00

URL: https://externals.io/message/48316#48321 · In reply to: #48316

Normally, PHP won't allow access types for interface methods, but the
reflection for SPL is defined inside the C code:

static const zend_function_entry spl_funcs_OuterIterator[] = {
        SPL_ABSTRACT_ME(OuterIterator, getInnerIterator,
arginfo_recursive_it_void)
        {NULL, NULL, NULL}
};

IMO the SPL_ME should be used instead, but I wouldn't be bothered about it ;-)

On Tue, May 18, 2010 at 11:12 PM, mathieu.suen
<mathieu.suen@easyflirt.com> wrote:
> Hi,
>
> In the SPL there is some interface that have abstract method:
>
> *Countable* {
> /* Methods */
> abstract public int count <http://www.php.net/manual/en/countable.count.php>
> ( void )
> }
>
> While some interface have "none abstract" method.
>
> *OuterIterator* extends Iterator
> <http://www.php.net/manual/en/class.iterator.php> {
> /* Methods */
> public Iterator getInnerIterator
> <http://www.php.net/manual/en/outeriterator.getchildren.php> ( void )
> ..snip..
> }
>
> Does  "abstract" keyword have a semantic?
>
> Thanks
>
> --Mathieu suen
>
>
>
>



-- 
--
Tjerk

---

## #48350 — mathieu.suen — 2010-05-19T12:27:17+00:00

URL: https://externals.io/message/48316#48350 · In reply to: #48321

Ok so there is no real meaning behind the "abstract".
Thanks


> Normally, PHP won't allow access types for interface methods, but the
> reflection for SPL is defined inside the C code:
>
> static const zend_function_entry spl_funcs_OuterIterator[] = {
>          SPL_ABSTRACT_ME(OuterIterator, getInnerIterator,
> arginfo_recursive_it_void)
>          {NULL, NULL, NULL}
> };
>
> IMO the SPL_ME should be used instead, but I wouldn't be bothered about it ;-)
>
> On Tue, May 18, 2010 at 11:12 PM, mathieu.suen
> <mathieu.suen@easyflirt.com>  wrote:
>    
> > […]
>
>
>    

-- Mathieu Suen

---

## #48351 — Richard Quadling — 2010-05-19T12:31:16+00:00

URL: https://externals.io/message/48316#48351 · In reply to: #48350

> Ok so there is no real meaning behind the "abstract".
> Thanks
>
> 
> > […]
>
> -- Mathieu Suen
>
>
>
>

Seemingly not when it applies to an interface.

-- 
-----
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling

---

## #48353 — Peter Cowburn — 2010-05-19T12:53:02+00:00

URL: https://externals.io/message/48316#48353 · In reply to: #48351

> 
> > […]

For what it's worth, the non-SPL interfaces use ZEND_ABSTRACT_ME or
similar as far as I can tell. Also, reflection says that all of the
interface methods are abstract (which they are, in the sense of not
having any method body).

> > […]
>
> Seemingly not when it applies to an interface.
>

I think the key issue is that _in the docs_ some interface methods are
marked up as abstract, yet others aren't.  I suggest making them
consistent, having them all being one or t'other.

> --
> -----
> Richard Quadling
> "Standing on the shoulders of some very clever giants!"
> EE : http://www.experts-exchange.com/M_248814.html
> EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
> Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
> ZOPA : http://uk.zopa.com/member/RQuadling

---

## #48354 — Richard Quadling — 2010-05-19T12:59:30+00:00

URL: https://externals.io/message/48316#48354 · In reply to: #48353

> I think the key issue is that _in the docs_ some interface methods are
> marked up as abstract, yet others aren't.  I suggest making them
> consistent, having them all being one or t'other.

I would show abstract.



-- 
-----
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling
