diff options
| author | Marcus Boerger <helly@php.net> | 2003-07-08 23:25:18 +0000 |
|---|---|---|
| committer | Marcus Boerger <helly@php.net> | 2003-07-08 23:25:18 +0000 |
| commit | f31df5693ec68b7dfa0b738f0356c382816f2abe (patch) | |
| tree | b4b829a947f9dd9c4b821a7a25cdf2e07705fac7 | |
| parent | 79ac007d20bd80b40d8ac70d996888b3c9c50847 (diff) | |
| download | php-git-f31df5693ec68b7dfa0b738f0356c382816f2abe.tar.gz | |
Currently we're presented all properties with foreach()
| -rwxr-xr-x | ext/spl/tests/foreach_non_spl.phpt | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/ext/spl/tests/foreach_non_spl.phpt b/ext/spl/tests/foreach_non_spl.phpt new file mode 100755 index 0000000000..bb2eed1c1e --- /dev/null +++ b/ext/spl/tests/foreach_non_spl.phpt @@ -0,0 +1,61 @@ +--TEST-- +SPL: foreach non spl classes +--SKIPIF-- +<?php if (0 && !extension_loaded("spl")) print "skip"; ?> +--FILE-- +<?php + +echo "1st try\n"; + +class c1 {} + +$obj = new c1(); + +foreach($obj as $w) { + echo "object:$w\n"; +} + +echo "2nd try\n"; + +class c2 { + + public $max = 3; + public $num = 0; + + function current() { + echo __METHOD__ . "\n"; + return $this->num; + } + function next() { + echo __METHOD__ . "\n"; + $this->num++; + } + function has_more() { + echo __METHOD__ . "\n"; + return $this->num < $this->max; + } + function key() { + echo __METHOD__ . "\n"; + switch($this->num) { + case 0: return "1st"; + case 1: return "2nd"; + case 2: return "3rd"; + default: return "???"; + } + } +} + +$obj = new c2(); + +foreach($obj as $v => $w) { + echo "object:$v=>$w\n"; +} + +print "Done\n"; +?> +--EXPECTF-- +1st try +2nd try +object:max=>3 +object:num=>0 +Done |
