Defining and Using an Interface
<?php interface Serializable { public function writeObject(); } class Point implements Serializable { public $x; public $y; public function writeObject() { return serialize( $this ); } } class Item implements Serializable { public function writeObject() { return serialize( $this ); } } class Serializer { private $sArray = array(); function register( Serializable $obj ) { $this->sArray[] = $obj; } function output() { foreach ( $this->sArray as $obj ) { print $obj->writeObject()."\n"; } } } $serializer = new Serializer(); $serializer->register( new Item() ); $serializer->register( new Point() ); print "<pre>"; $serializer->output(); print "</pre>"; ?>