⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 iterator_001.phpt

📁 PHP v6.0 For Linux 运行环境:Win9X/ WinME/ WinNT/ Win2K/ WinXP
💻 PHPT
字号:
--TEST--SPL: Iterator aggregating inner iterator's methods--SKIPIF--<?php if (!extension_loaded("spl")) print "skip"; ?>--FILE--<?phpclass NumericArrayIterator implements Iterator{	protected $a;	protected $i = 0;	public function __construct($a)	{		echo __METHOD__ . "\n";		$this->a = $a;	}	public function rewind()	{		echo __METHOD__ . "\n";		$this->i = 0;	}	public function valid()	{		$ret = $this->i < count($this->a);		echo __METHOD__ . '(' . ($ret ? 'true' : 'false') . ")\n";		return $ret;	}	public function key()	{		echo __METHOD__ . "\n";		return $this->i;	}	public function current()	{		echo __METHOD__ . "\n";		return $this->a[$this->i];	}	public function next()	{		echo __METHOD__ . "\n";		$this->i++;	}		public function greaterThan($comp)	{		echo get_class($this) . '::' . __FUNCTION__ . '(' . $comp . ")\n";		return $this->current() > $comp;	}}class SeekableNumericArrayIterator extends NumericArrayIterator implements SeekableIterator{	public function seek($index)	{		if ($index < count($this->a)) {			$this->i = $index;		}		echo __METHOD__ . '(' . $index . ")\n";	}}$a = array(1, 2, 3, 4, 5);$it = new LimitIterator(new NumericArrayIterator($a), 1, 3);foreach ($it as $v){	print $v . ' is ' . ($it->greaterThan(2) ? 'greater than 2' : 'less than or equal 2') . "\n";}echo "===SEEKABLE===\n";$a = array(1, 2, 3, 4, 5);$it = new LimitIterator(new SeekableNumericArrayIterator($a), 1, 3);foreach($it as $v){	print $v . ' is ' . ($it->greaterThan(2) ? 'greater than 2' : 'less than or equal 2') . "\n";}echo "===STACKED===\n";echo "Shows '2 is greater than 2' because the test is actually done with the current value which is 3.\n";$a = array(1, 2, 3, 4, 5);$it = new CachingIterator(new LimitIterator(new SeekableNumericArrayIterator($a), 1, 3));foreach($it as $v){	print $v . ' is ' . ($it->greaterThan(2) ? 'greater than 2' : 'less than or equal 2') . "\n";}?>===DONE===<?php exit(0); ?>--EXPECT--NumericArrayIterator::__constructNumericArrayIterator::rewindNumericArrayIterator::valid(true)NumericArrayIterator::nextNumericArrayIterator::valid(true)NumericArrayIterator::valid(true)NumericArrayIterator::currentNumericArrayIterator::keyNumericArrayIterator::greaterThan(2)NumericArrayIterator::current2 is less than or equal 2NumericArrayIterator::nextNumericArrayIterator::valid(true)NumericArrayIterator::currentNumericArrayIterator::keyNumericArrayIterator::greaterThan(2)NumericArrayIterator::current3 is greater than 2NumericArrayIterator::nextNumericArrayIterator::valid(true)NumericArrayIterator::currentNumericArrayIterator::keyNumericArrayIterator::greaterThan(2)NumericArrayIterator::current4 is greater than 2NumericArrayIterator::next===SEEKABLE===NumericArrayIterator::__constructNumericArrayIterator::rewindSeekableNumericArrayIterator::seek(1)NumericArrayIterator::valid(true)NumericArrayIterator::currentNumericArrayIterator::keySeekableNumericArrayIterator::greaterThan(2)NumericArrayIterator::current2 is less than or equal 2NumericArrayIterator::nextNumericArrayIterator::valid(true)NumericArrayIterator::currentNumericArrayIterator::keySeekableNumericArrayIterator::greaterThan(2)NumericArrayIterator::current3 is greater than 2NumericArrayIterator::nextNumericArrayIterator::valid(true)NumericArrayIterator::currentNumericArrayIterator::keySeekableNumericArrayIterator::greaterThan(2)NumericArrayIterator::current4 is greater than 2NumericArrayIterator::next===STACKED===Shows '2 is greater than 2' because the test is actually done with the current value which is 3.NumericArrayIterator::__constructNumericArrayIterator::rewindSeekableNumericArrayIterator::seek(1)NumericArrayIterator::valid(true)NumericArrayIterator::currentNumericArrayIterator::keyNumericArrayIterator::nextNumericArrayIterator::valid(true)NumericArrayIterator::currentNumericArrayIterator::keySeekableNumericArrayIterator::greaterThan(2)NumericArrayIterator::current2 is greater than 2NumericArrayIterator::nextNumericArrayIterator::valid(true)NumericArrayIterator::currentNumericArrayIterator::keySeekableNumericArrayIterator::greaterThan(2)NumericArrayIterator::current3 is greater than 2NumericArrayIterator::nextSeekableNumericArrayIterator::greaterThan(2)NumericArrayIterator::current4 is greater than 2===DONE===

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -