select( * 'user', '*', $conds, $opts, __METHOD__ * ) ); * foreach( $users as $user ) { * ...use $user's methods here, it's a User object!... * } */ abstract class ObjectArray implements Iterator { static function newFromClassAndResult( $class, $res ) { $array = null; if ( !wfRunHooks( 'ObjectArrayFromResult', array( $class, &$array, $res ) ) ) { return null; } if ( $array === null ) { $array = self::newFromResult_internal( $class, $res ); } return $array; } protected static function newFromResult_internal( $class, $res ) { return new ObjectArrayFromResult( $class, $res ); } } class ObjectArrayFromResult extends ObjectArray { var $res, $class; var $key = 0, $current = false; function __construct( $class, $res ) { $this->class = $class; $this->res = $res; $this->key = 0; $this->setCurrent( $this->res->current() ); } protected function setCurrent( $row ) { if ( $row === false ) { $this->current = false; } else { $this->current = call_user_func( array( $this->class, 'newFromRow' ), $row ); } } public function count() { return $this->res->numRows(); } function current() { return $this->current; } function key() { return $this->key; } function next() { $row = $this->res->next(); $this->setCurrent( $row ); $this->key++; } function rewind() { $this->res->rewind(); $this->key = 0; $this->setCurrent( $this->res->current() ); } function valid() { return $this->current !== false; } } abstract class UserArray extends ObjectArray { static function newFromResult( $res ) { return parent::newFromClassAndResult( 'User', $res ); } } abstract class TitleArray extends ObjectArray { static function newFromResult( $res ) { return parent::newFromClassAndResult( 'Title', $res ); } }