]> granicus.if.org Git - php/commitdiff
Add foreach/continue test
authorMarcus Boerger <helly@php.net>
Sun, 10 Aug 2003 13:17:02 +0000 (13:17 +0000)
committerMarcus Boerger <helly@php.net>
Sun, 10 Aug 2003 13:17:02 +0000 (13:17 +0000)
ext/spl/tests/foreach_continue.phpt [new file with mode: 0755]

diff --git a/ext/spl/tests/foreach_continue.phpt b/ext/spl/tests/foreach_continue.phpt
new file mode 100755 (executable)
index 0000000..aa8b40f
--- /dev/null
@@ -0,0 +1,102 @@
+--TEST--
+SPL: foreach and break
+--SKIPIF--
+<?php if (!extension_loaded("spl")) print "skip"; ?>
+--FILE--
+<?php
+class c_iter implements spl_forward {
+
+       private $obj;
+       private $num = 0;
+
+       function __construct($obj) {
+               $this->obj = $obj;
+       }
+       function current() {
+               echo __METHOD__ . "\n";
+               return $this->num;
+       }
+       function next() {
+               echo __METHOD__ . "\n";
+               $this->num++;
+       }
+       function has_more() {
+               $more = $this->num < $this->obj->max;
+               echo __METHOD__ . ' = ' .($more ? 'true' : 'false') . "\n";
+               return $more;
+       }
+}
+       
+class c implements spl_iterator {
+
+       public $max = 4;
+
+       function new_iterator() {
+               echo __METHOD__ . "\n";
+               return new c_iter($this);
+       }
+}
+
+$t = new c();
+
+foreach($t as $v) {
+       if ($v == 0) {
+               echo "continue outer\n";
+               continue;
+       }
+       foreach($t as $w) {
+               if ($w == 1) {
+                       echo "continue inner\n";
+                       continue;
+               }
+               if ($w == 2) {
+                       echo "break inner\n";
+                       break;
+               }
+               echo "double:$v:$w\n";
+       }
+       if ($v == 2) {
+               echo "break outer\n";
+               break;
+       }
+}
+
+print "Done\n";
+?>
+--EXPECT--
+c::new_iterator
+c_iter::has_more = true
+c_iter::current
+continue outer
+c_iter::next
+c_iter::has_more = true
+c_iter::current
+c::new_iterator
+c_iter::has_more = true
+c_iter::current
+double:1:0
+c_iter::next
+c_iter::has_more = true
+c_iter::current
+continue inner
+c_iter::next
+c_iter::has_more = true
+c_iter::current
+break inner
+c_iter::next
+c_iter::has_more = true
+c_iter::current
+c::new_iterator
+c_iter::has_more = true
+c_iter::current
+double:2:0
+c_iter::next
+c_iter::has_more = true
+c_iter::current
+continue inner
+c_iter::next
+c_iter::has_more = true
+c_iter::current
+break inner
+break outer
+Done