From: Marcus Boerger Date: Sun, 25 May 2003 19:24:29 +0000 (+0000) Subject: Add a testcase to foreach/break X-Git-Tag: RELEASE_1_0_2~596 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0b4cbe26a7aaf17be72249ca0971c1c0d5874a83;p=php Add a testcase to foreach/break --- diff --git a/ext/spl/tests/foreach_break.phpt b/ext/spl/tests/foreach_break.phpt new file mode 100755 index 0000000000..f1c7b27218 --- /dev/null +++ b/ext/spl/tests/foreach_break.phpt @@ -0,0 +1,90 @@ +--TEST-- +SPL: foreach and break +--SKIPIF-- + +--FILE-- +obj = $obj; + } + function current() { + echo __CLASS__ . '::' . __FUNCTION__ . "\n"; + return $this->num; + } + function next() { + echo __CLASS__ . '::' . __FUNCTION__ . "\n"; + $this->num++; + } + function has_more() { + $more = $this->num < $this->obj->max; + echo __CLASS__ . '::' . __FUNCTION__ . ' = ' .($more ? 'true' : 'false') . "\n"; + return $more; + } + function key() { + echo __CLASS__ . '::' . __FUNCTION__ . "\n"; + switch($this->num) { + case 0: return "1st"; + case 1: return "2nd"; + case 2: return "3rd"; + default: return "???"; + } + } +} + +class c implements spl::iterator { + + public $max = 3; + + function new_iterator() { + echo __CLASS__ . '::' . __FUNCTION__ . "\n"; + return new c_iter($this); + } +} + +$t = new c(); + +foreach($t as $v) { + foreach($t as $w) { + echo "double:$v:$w\n"; + break; + } +} + +print "Done\n"; +?> +--EXPECT-- +c::new_iterator +c_iter::has_more = true +c_iter::current +c_iter::key +c::new_iterator +c_iter::has_more = true +c_iter::current +c_iter::key +double:0:0 +c_iter::next +c_iter::has_more = true +c_iter::current +c_iter::key +c::new_iterator +c_iter::has_more = true +c_iter::current +c_iter::key +double:1:0 +c_iter::next +c_iter::has_more = true +c_iter::current +c_iter::key +c::new_iterator +c_iter::has_more = true +c_iter::current +c_iter::key +double:2:0 +c_iter::next +c_iter::has_more = false +Done