Monthly Archives: July 2012

PHP内部Interfaces

可以使用get_declared_interfaces获得当前php中的interface

1. Traversable (遍历接口)
无法单独实现. 比如由 IteratorAggregate 或 Iterator 接口实现

2. IteratorAggregate (聚合式迭代器)
创建一个外部迭代器的接口

IteratorAggregate extends Traversable {
abstract public Traversable getIterator ( void )
}

3. Iterator (迭代器)
可在内部迭代自己的外部迭代器或类的接口。

Iterator extends Traversable {
abstract public mixed current ( void )
abstract public scalar key ( void )
abstract public void next ( void )
abstract public void rewind ( void )
abstract public boolean valid ( void )
}

4. ArrayAccess (数组式访问)
提供像访问数组一样访问对象的能力的接口。

ArrayAccess {
abstract public boolean offsetExists ( mixed $offset )
abstract public mixed offsetGet ( mixed $offset )
abstract public void offsetSet ( mixed $offset , mixed $value )
abstract public void offsetUnset ( mixed $offset )
}

5. Serializable (序列化)
自定义序列化的接口。

实现此接口的类将不再支持 __sleep() 和 __wakeup()。不论何时,只要有实例需要被序列化,serialize 方法都将被调用。它将不会调用 __destruct() 或有其他影响,除非程序化地调用此方法。当数据被反序列化时,类将被感知并且调用合适的 unserialize() 方法而不是调用 __construct()。如果需要执行标准的构造器,你应该在这个方法中进行处理。

Serializable {
abstract public string serialize ( void )
abstract public mixed unserialize ( string $serialized )
}

6. Reflector (反射接口)
反射接口实现导出类

Reflector {
abstract public static string export ( void )
abstract public string __toString ( void )
}

7. RecursiveIterator (递归式迭代)

RecursiveIterator extends Iterator {
//Returns an iterator for the current entry.
public RecursiveIterator getChildren ( void )
//Returns if an iterator can be created fot the current entry.
public bool hasChildren ( void )

abstract public mixed Iterator::current ( void )
abstract public scalar Iterator::key ( void )
abstract public void Iterator::next ( void )
abstract public void Iterator::rewind ( void )
abstract public boolean Iterator::valid ( void )
}

8. OuterIterator (外层迭代器)

OuterIterator extends Iterator {

//Returns the inner iterator for the current entry.
public Iterator getInnerIterator ( void )

abstract public mixed Iterator::current ( void )
abstract public scalar Iterator::key ( void )
abstract public void Iterator::next ( void )
abstract public void Iterator::rewind ( void )
abstract public boolean Iterator::valid ( void )
}

9. Countable
当使用count函数式, 将被调用

Countable {
abstract public int count ( void )
}

10. SeekableIterator(可寻迭代器)

SeekableIterator extends Iterator {
//seek position
abstract public void seek ( int $position )

abstract public mixed Iterator::current ( void )
abstract public scalar Iterator::key ( void )
abstract public void Iterator::next ( void )
abstract public void Iterator::rewind ( void )
abstract public boolean Iterator::valid ( void )
}

11. ArrayObject
Object像array一样工作

ArrayObject implements IteratorAggregate , Traversable , ArrayAccess , Serializable , Countable {

const integer STD_PROP_LIST = 1 ;
const integer ARRAY_AS_PROPS = 2 ;

public __construct ([ mixed $input [, int $flags = 0 [, string $iterator_class = "ArrayIterator" ]]] )
public void append ( mixed $value )
public void asort ( void )
public int count ( void )
public array exchangeArray ( mixed $input )
public array getArrayCopy ( void )
public int getFlags ( void )
public ArrayIterator getIterator ( void )
public string getIteratorClass ( void )
public void ksort ( void )
public void natcasesort ( void )
public void natsort ( void )
public bool offsetExists ( mixed $index )
public mixed offsetGet ( mixed $index )
public void offsetSet ( mixed $index , mixed $newval )
public void offsetUnset ( mixed $index )
public void serialize ( void )
public void setFlags ( int $flags )
public void setIteratorClass ( string $iterator_class )
public void uasort ( callable $cmp_function )
public void uksort ( callable $cmp_function )
public void unserialize ( string $serialized )
}

更详细参考http://us.php.net/manual/zh/intro.spl.php