};
/* }}} */
-zend_class_entry *spl_ce_recursive_it;
-zend_class_entry *spl_ce_recursive_it_it;
-zend_class_entry *spl_ce_array_read;
-zend_class_entry *spl_ce_array_access;
-
/* {{{ spl_functions_none
*/
function_entry spl_functions_none[] = {
{
SPL_DEBUG(fprintf(stderr, "%s\n", "Shutting down SPL");)
-#ifdef SPL_FOREACH
- ZEND_EXECUTE_HOOK_RESTORE(ZEND_FE_RESET);
- ZEND_EXECUTE_HOOK_RESTORE(ZEND_FE_FETCH);
- ZEND_EXECUTE_HOOK_RESTORE(ZEND_SWITCH_FREE);
-#endif
-
-#if defined(SPL_ARRAY_READ) | defined(SPL_ARRAY_WRITE)
- ZEND_EXECUTE_HOOK_RESTORE(ZEND_FETCH_DIM_R);
- ZEND_EXECUTE_HOOK_RESTORE(ZEND_FETCH_DIM_W);
- ZEND_EXECUTE_HOOK_RESTORE(ZEND_FETCH_DIM_RW);
-#endif
-
-#ifdef SPL_ARRAY_WRITE
- ZEND_EXECUTE_HOOK_RESTORE(ZEND_ASSIGN_DIM);
-#endif /* SPL_ARRAY_WRITE */
-
return SUCCESS;
}
/* }}} */
*/
PHP_MINFO_FUNCTION(spl)
{
-#ifdef SPL_FOREACH
- char *foreach = "beta";
-#else /* SPL_ARRAY_WRITE */
- char *foreach = "beta, not hooked";
-#endif
-#ifdef SPL_ARRAY_READ
- char *array_read = "beta";
-#else /* SPL_ARRAY_WRITE */
- char *array_read = "beta, not hooked";
-#endif
-#ifdef SPL_ARRAY_WRITE
- char *array_write = "beta";
-#else /* SPL_ARRAY_WRITE */
- char *array_write = "beta, not hooked";
-#endif /* SPL_ARRAY_WRITE */
-
php_info_print_table_start();
php_info_print_table_header(2, "SPL support", "enabled");
- php_info_print_table_row(2, "iterator", foreach);
- php_info_print_table_row(2, "forward", foreach);
- php_info_print_table_row(2, "sequence", foreach);
- php_info_print_table_row(2, "assoc", foreach);
- php_info_print_table_row(2, "ArrayRead", array_read);
- php_info_print_table_row(2, "ArrayAccess", array_write);
php_info_print_table_end();
}
/* }}} */
PHP_RSHUTDOWN_FUNCTION(spl);
PHP_MINFO_FUNCTION(spl);
-#define ZEND_EXECUTE_HOOK_PTR(name) \
- opcode_handler_t handler_ ## name
-
-#define ZEND_EXECUTE_HOOK(name) \
- spl_globals->handler_ ## name = zend_opcode_handlers[name]; \
- zend_opcode_handlers[name] = spl_handler_ ## name
-
-#define ZEND_EXECUTE_HOOK_RESTORE(name) \
- zend_opcode_handlers[name] = SPL_G(handler_ ## name)
-
-#define ZEND_EXECUTE_HOOK_ORIGINAL(name) \
- return SPL_G(handler_ ## name)(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU)
-
-#define ZEND_EXECUTE_HOOK_FUNCTION(name) \
- int spl_handler_ ## name(ZEND_OPCODE_HANDLER_ARGS)
ZEND_BEGIN_MODULE_GLOBALS(spl)
-#ifdef SPL_FOREACH
- ZEND_EXECUTE_HOOK_PTR(ZEND_FE_RESET);
- ZEND_EXECUTE_HOOK_PTR(ZEND_FE_FETCH);
- ZEND_EXECUTE_HOOK_PTR(ZEND_SWITCH_FREE);
-#endif
-#if defined(SPL_ARRAY_READ) | defined(SPL_ARRAY_WRITE)
- ZEND_EXECUTE_HOOK_PTR(ZEND_FETCH_DIM_R);
- ZEND_EXECUTE_HOOK_PTR(ZEND_FETCH_DIM_W);
- ZEND_EXECUTE_HOOK_PTR(ZEND_FETCH_DIM_RW);
-#endif
-#ifdef SPL_ARRAY_WRITE
- ZEND_EXECUTE_HOOK_PTR(ZEND_ASSIGN_DIM);
- ZEND_EXECUTE_HOOK_PTR(ZEND_UNSET_DIM_OBJ);
-#endif
ZEND_END_MODULE_GLOBALS(spl)
#ifdef ZTS
}
/* }}} */
-/* {{{ proto void spl_array::__construct(array|object ar = array())
- proto void spl_array_it::__construct(array|object ar = array())
+/* {{{ proto void ArrayObject::__construct(array|object ar = array())
+ proto void ArrayIterator::__construct(array|object ar = array())
Cronstructs a new array iterator from a path. */
SPL_METHOD(Array, __construct)
{
}
/* }}} */
-/* {{{ proto spl_array_it|NULL ArrayObject::getIterator()
+/* {{{ proto ArrayIterator ArrayObject::getIterator()
Create a new iterator from a ArrayObject instance */
SPL_METHOD(Array, getIterator)
{
}
/* }}} */
-/* {{{ proto void spl_array_it::rewind()
+/* {{{ proto void ArrayIterator::rewind()
Rewind array back to the start */
SPL_METHOD(Array, rewind)
{
}
/* }}} */
-/* {{{ proto mixed|false spl_array_it::current()
+/* {{{ proto mixed|false ArrayIterator::current()
Return current array entry */
SPL_METHOD(Array, current)
{
}
/* }}} */
-/* {{{ proto mixed|false spl_array_it::key()
+/* {{{ proto mixed|false ArrayIterator::key()
Return current array key */
SPL_METHOD(Array, key)
{
}
/* }}} */
-/* {{{ proto void spl_array_it::next()
+/* {{{ proto void ArrayIterator::next()
Move to next entry */
SPL_METHOD(Array, next)
{
}
/* }}} */
-/* {{{ proto bool spl_array_it::hasMore()
+/* {{{ proto bool ArrayIterator::hasMore()
Check whether array contains more entries */
SPL_METHOD(Array, hasMore)
{
}
/* }}} */
-#define spl_call_method_0(obj, obj_ce, fn_proxy, function_name, fname_len, retval) \
- spl_call_method(obj, obj_ce, fn_proxy, function_name, fname_len, retval, 0, NULL, NULL TSRMLS_CC)
-
-#define spl_call_method_1(obj, obj_ce, fn_proxy, function_name, fname_len, retval, arg1) \
- spl_call_method(obj, obj_ce, fn_proxy, function_name, fname_len, retval, 1, arg1, NULL TSRMLS_CC)
-
-#define spl_call_method_2(obj, obj_ce, fn_proxy, function_name, fname_len, retval, arg1, arg2) \
- spl_call_method(obj, obj_ce, fn_proxy, function_name, fname_len, retval, 2, arg1, arg2 TSRMLS_CC)
-
void spl_instantiate(zend_class_entry *pce, zval **object, int alloc TSRMLS_DC);
int spl_instantiate_arg_ex1(zend_class_entry *pce, zval **retval, int alloc, zval *arg1 TSRMLS_DC);
int spl_instantiate_arg_ex2(zend_class_entry *pce, zval **retval, int alloc, zval *arg1, zval *arg2 TSRMLS_DC);
+++ /dev/null
---TEST--
-SPL: array_access
---SKIPIF--
-<?php
- if (!extension_loaded("spl")) die("skip");
- if (!in_array("ArrayAccess", spl_classes())) die("skip spl_array_access not present");
-?>
---FILE--
-<?php
-class c implements ArrayAccess {
-
- public $a = array('1st', 1, 2=>'3rd', '4th'=>4);
- function exists($index) {
- echo __METHOD__ . "($index)\n";
- return array_key_exists($index, $this->a);
- }
- function get($index) {
- echo __METHOD__ . "($index)\n";
- return $this->a[$index];
- }
- function set($index, $newval) {
- echo __METHOD__ . "($index,$newval)\n";
- return $this->a[$index] = $newval;
- }
- function del($index) {
- echo __METHOD__ . "($index)\n";
- unset($this->a[$index]);
- }
-}
-
-$obj = new c();
-
-var_dump($obj->a);
-
-var_dump($obj[0]);
-var_dump($obj[1]);
-var_dump($obj[2]);
-var_dump($obj['4th']);
-var_dump($obj['5th']);
-var_dump($obj[6]);
-
-echo "WRITE 1\n";
-$obj[1] = 'Changed 1';
-var_dump($obj[1]);
-echo "WRITE 2\n";
-$obj['4th'] = 'Changed 4th';
-var_dump($obj['4th']);
-echo "WRITE 3\n";
-$obj['5th'] = 'Added 5th';
-var_dump($obj['5th']);
-echo "WRITE 4\n";
-$obj[6] = 'Added 6';
-var_dump($obj[6]);
-
-var_dump($obj[0]);
-var_dump($obj[2]);
-
-$x = $obj[6] = 'changed 6';
-var_dump($obj[6]);
-var_dump($x);
-
-echo "===unset===\n";
-var_dump($obj->a);
-unset($obj[2]);
-unset($obj['4th']);
-unset($obj[7]);
-unset($obj['8th']);
-var_dump($obj->a);
-
-print "Done\n";
-?>
---EXPECTF--
-array(4) {
- [0]=>
- string(3) "1st"
- [1]=>
- int(1)
- [2]=>
- string(3) "3rd"
- ["4th"]=>
- int(4)
-}
-c::exists(0)
-c::get(0)
-string(3) "1st"
-c::exists(1)
-c::get(1)
-int(1)
-c::exists(2)
-c::get(2)
-string(3) "3rd"
-c::exists(4th)
-c::get(4th)
-int(4)
-c::exists(5th)
-
-Notice: Undefined index: 5th in %sarray_access_001.php on line %d
-NULL
-c::exists(6)
-
-Notice: Undefined index: 6 in %sarray_access_001.php on line %d
-NULL
-WRITE 1
-c::set(1,Changed 1)
-c::exists(1)
-c::get(1)
-string(9) "Changed 1"
-WRITE 2
-c::set(4th,Changed 4th)
-c::exists(4th)
-c::get(4th)
-string(11) "Changed 4th"
-WRITE 3
-c::set(5th,Added 5th)
-c::exists(5th)
-c::get(5th)
-string(9) "Added 5th"
-WRITE 4
-c::set(6,Added 6)
-c::exists(6)
-c::get(6)
-string(7) "Added 6"
-c::exists(0)
-c::get(0)
-string(3) "1st"
-c::exists(2)
-c::get(2)
-string(3) "3rd"
-c::set(6,changed 6)
-c::exists(6)
-c::get(6)
-string(9) "changed 6"
-string(9) "changed 6"
-===unset===
-array(6) {
- [0]=>
- string(3) "1st"
- [1]=>
- string(9) "Changed 1"
- [2]=>
- string(3) "3rd"
- ["4th"]=>
- string(11) "Changed 4th"
- ["5th"]=>
- string(9) "Added 5th"
- [6]=>
- string(9) "changed 6"
-}
-c::del(2)
-c::del(4th)
-c::del(7)
-c::del(8th)
-array(4) {
- [0]=>
- string(3) "1st"
- [1]=>
- string(9) "Changed 1"
- ["5th"]=>
- string(9) "Added 5th"
- [6]=>
- string(9) "changed 6"
-}
-Done
+++ /dev/null
---TEST--
-SPL: array_access without return in set()
---SKIPIF--
-<?php
- if (!extension_loaded("spl")) die("skip");
- if (!in_array("spl_array_access", spl_classes())) die("skip spl_array_access not present");
-?>
---FILE--
-<?php
-class c implements spl_array_access {
-
- public $a = array('1st', 1, 2=>'3rd', '4th'=>4);
-
- function exists($index) {
- echo __METHOD__ . "($index)\n";
- return array_key_exists($index, $this->a);
- }
- function get($index) {
- echo __METHOD__ . "($index)\n";
- return $this->a[$index];
- }
- function set($index, $newval) {
- echo __METHOD__ . "($index,$newval)\n";
- /* return */ $this->a[$index] = $newval;
- }
- function del($index) {
- echo __METHOD__ . "($index)\n";
- unset($this->a[$index]);
- }
-}
-
-$obj = new c();
-
-var_dump($obj->a);
-
-var_dump($obj[0]);
-var_dump($obj[1]);
-var_dump($obj[2]);
-var_dump($obj['4th']);
-var_dump($obj['5th']);
-var_dump($obj[6]);
-
-echo "WRITE 1\n";
-$obj[1] = 'Changed 1';
-var_dump($obj[1]);
-echo "WRITE 2\n";
-$obj['4th'] = 'Changed 4th';
-var_dump($obj['4th']);
-echo "WRITE 3\n";
-$obj['5th'] = 'Added 5th';
-var_dump($obj['5th']);
-echo "WRITE 4\n";
-$obj[6] = 'Added 6';
-var_dump($obj[6]);
-
-var_dump($obj[0]);
-var_dump($obj[2]);
-
-$x = $obj[6] = 'changed 6';
-var_dump($obj[6]);
-var_dump($x);
-
-print "Done\n";
-?>
---EXPECTF--
-array(4) {
- [0]=>
- string(3) "1st"
- [1]=>
- int(1)
- [2]=>
- string(3) "3rd"
- ["4th"]=>
- int(4)
-}
-c::exists(0)
-c::get(0)
-string(3) "1st"
-c::exists(1)
-c::get(1)
-int(1)
-c::exists(2)
-c::get(2)
-string(3) "3rd"
-c::exists(4th)
-c::get(4th)
-int(4)
-c::exists(5th)
-
-Notice: Undefined index: 5th in %sarray_access_002.php on line %d
-NULL
-c::exists(6)
-
-Notice: Undefined index: 6 in %sarray_access_002.php on line %d
-NULL
-WRITE 1
-c::set(1,Changed 1)
-
-Warning: Method c::set() did not return a value, using input value in %sarray_access_002.php on line %d
-c::exists(1)
-c::get(1)
-string(9) "Changed 1"
-WRITE 2
-c::set(4th,Changed 4th)
-
-Warning: Method c::set() did not return a value, using input value in %sarray_access_002.php on line %d
-c::exists(4th)
-c::get(4th)
-string(11) "Changed 4th"
-WRITE 3
-c::set(5th,Added 5th)
-
-Warning: Method c::set() did not return a value, using input value in %sarray_access_002.php on line %d
-c::exists(5th)
-c::get(5th)
-string(9) "Added 5th"
-WRITE 4
-c::set(6,Added 6)
-
-Warning: Method c::set() did not return a value, using input value in %sarray_access_002.php on line %d
-c::exists(6)
-c::get(6)
-string(7) "Added 6"
-c::exists(0)
-c::get(0)
-string(3) "1st"
-c::exists(2)
-c::get(2)
-string(3) "3rd"
-c::set(6,changed 6)
-
-Warning: Method c::set() did not return a value, using input value in %sarray_access_002.php on line %d
-c::exists(6)
-c::get(6)
-string(9) "changed 6"
-string(9) "changed 6"
-Done
--TEST--
-SPL: spl_array_iterator
+SPL: ArrayIterator
--SKIPIF--
<?php if (!extension_loaded("spl")) print "skip"; ?>
--FILE--
echo "==Normal==\n";
$arr = array(0=>0, 1=>1, 2=>2);
-$obj = new spl_array($arr);
+$obj = new ArrayObject($arr);
foreach($obj as $ak=>$av) {
foreach($obj as $bk=>$bv) {
echo "==UseRef==\n";
$arr = array(0=>0, 1=>1, 2=>2);
-$obj = new spl_array(&$arr);
+$obj = new ArrayObject(&$arr);
foreach($obj as $ak=>$av) {
foreach($obj as $bk=>$bv) {
echo "==Modify==\n";
$arr = array(0=>0, 1=>1, 2=>2);
-$obj = new spl_array(&$arr);
+$obj = new ArrayObject(&$arr);
foreach($obj as $ak=>$av) {
foreach($obj as $bk=>$bv) {
echo "==Delete==\n";
$arr = array(0=>0, 1=>1, 2=>2);
-$obj = new spl_array(&$arr);
+$obj = new ArrayObject(&$arr);
foreach($obj as $ak=>$av) {
foreach($obj as $bk=>$bv) {
echo "==Change==\n";
$arr = array(0=>0, 1=>1, 2=>2);
-$obj = new spl_array(&$arr);
+$obj = new ArrayObject(&$arr);
foreach($obj as $ak=>$av) {
foreach($obj as $bk=>$bv) {
1=>1 - 0=>0
1=>1 - 1=>1
-Notice: spl_array_it::next(): Array was modified outside object and internal position is no longer valid in %sarray_iterator.php on line %d
+Notice: ArrayIterator::next(): Array was modified outside object and internal position is no longer valid in %sarray_iterator.php on line %d
1=>1 - 0=>0
1=>1 - 2=>2
-Notice: spl_array_it::next(): Array was modified outside object and internal position is no longer valid in %sarray_iterator.php on line %d
+Notice: ArrayIterator::next(): Array was modified outside object and internal position is no longer valid in %sarray_iterator.php on line %d
0=>0 - 0=>0
0=>0 - 2=>2
2=>2 - 0=>0
1=>1 - 0=>0
1=>1 - 1=>1
-Notice: spl_array_it::next(): Array was modified outside object and is no longer an array in %sarray_iterator.php on line %d
+Notice: ArrayIterator::next(): Array was modified outside object and is no longer an array in %sarray_iterator.php on line %d
-Notice: spl_array_it::hasMore(): Array was modified outside object and is no longer an array in %sarray_iterator.php on line %d
+Notice: ArrayIterator::hasMore(): Array was modified outside object and is no longer an array in %sarray_iterator.php on line %d
-Notice: spl_array_it::next(): Array was modified outside object and is no longer an array in %sarray_iterator.php on line %d
+Notice: ArrayIterator::next(): Array was modified outside object and is no longer an array in %sarray_iterator.php on line %d
-Notice: spl_array_it::hasMore(): Array was modified outside object and is no longer an array in %sarray_iterator.php on line %d
+Notice: ArrayIterator::hasMore(): Array was modified outside object and is no longer an array in %sarray_iterator.php on line %d
Done
--TEST--
-SPL: array
+SPL: ArrayObject
--SKIPIF--
<?php if (!extension_loaded("spl")) print "skip"; ?>
--FILE--
}
int(0)
-Notice: Undefined offset: 6 in %sarray.php on line %d
+Notice: Undefined offset: 6 in %sarray_object.php on line %d
NULL
-Notice: Undefined index: b in %sarray.php on line %d
+Notice: Undefined index: b in %sarray_object.php on line %d
NULL
-Notice: Undefined offset: 7 in %sarray.php on line %d
+Notice: Undefined offset: 7 in %sarray_object.php on line %d
-Notice: Undefined index: c in %sarray.php on line %d
+Notice: Undefined index: c in %sarray_object.php on line %d
object(ArrayObject)#1 (2) {
[0]=>
int(0)
+++ /dev/null
---TEST--
-SPL: array_read
---SKIPIF--
-<?php if (!extension_loaded("spl")) print "skip"; ?>
---FILE--
-<?php
-
-echo "EXTERNAL\n";
-
-$a = array('1st', 1, 2=>'3rd', '4th'=>4);
-var_dump($a);
-
-class external implements spl_array_read {
-
- function exists($index) {
- echo __METHOD__ . "($index)\n";
- return array_key_exists($index, $GLOBALS['a']);
- }
-
- function get($index) {
- echo __METHOD__ . "($index)\n";
- return $GLOBALS['a'][$index];
- }
-}
-
-$obj = new external();
-
-var_dump($obj->get(0));
-var_dump($obj->get(1));
-var_dump($obj->get(2));
-var_dump($obj->get('4th'));
-var_dump($obj->get('5th'));
-var_dump($obj->get(6));
-
-var_dump($obj[0]);
-var_dump($obj[1]);
-var_dump($obj[2]);
-var_dump($obj['4th']);
-var_dump($obj['5th']);
-var_dump($obj[6]);
-
-$out = $obj[0]; echo "$out\n";
-$out = $obj[1]; echo "$out\n";
-$out = $obj[2]; echo "$out\n";
-$out = $obj['4th']; echo "$out\n";
-
-echo "INTERNAL\n";
-
-class internal implements spl_array_read {
-
- public $a = array('1st', 1, 2=>'3rd', '4th'=>4);
-
- function exists($index) {
- echo __METHOD__ . "($index)\n";
- return array_key_exists($index, $GLOBALS['a']);
- }
-
- function get($index) {
- echo __METHOD__ . "($index)\n";
- return $GLOBALS['a'][$index];
- }
-}
-
-$obj = new internal();
-
-var_dump($obj->a);
-
-var_dump($obj->get(0));
-var_dump($obj->get(1));
-var_dump($obj->get(2));
-var_dump($obj->get('4th'));
-var_dump($obj->get('5th'));
-var_dump($obj->get(6));
-
-var_dump($obj[0]);
-var_dump($obj[1]);
-var_dump($obj[2]);
-var_dump($obj['4th']);
-var_dump($obj['5th']);
-var_dump($obj[6]);
-
-$out = $obj[0]; echo "$out\n";
-$out = $obj[1]; echo "$out\n";
-$out = $obj[2]; echo "$out\n";
-$out = $obj['4th']; echo "$out\n";
-
-print "Done\n";
-?>
---EXPECTF--
-EXTERNAL
-array(4) {
- [0]=>
- string(3) "1st"
- [1]=>
- int(1)
- [2]=>
- string(3) "3rd"
- ["4th"]=>
- int(4)
-}
-external::get(0)
-string(3) "1st"
-external::get(1)
-int(1)
-external::get(2)
-string(3) "3rd"
-external::get(4th)
-int(4)
-external::get(5th)
-
-Notice: Undefined index: 5th in %s on line %d
-NULL
-external::get(6)
-
-Notice: Undefined offset: 6 in %s on line %d
-NULL
-external::exists(0)
-external::get(0)
-string(3) "1st"
-external::exists(1)
-external::get(1)
-int(1)
-external::exists(2)
-external::get(2)
-string(3) "3rd"
-external::exists(4th)
-external::get(4th)
-int(4)
-external::exists(5th)
-
-Notice: Undefined index: 5th in %s on line %d
-NULL
-external::exists(6)
-
-Notice: Undefined index: 6 in %s on line %d
-NULL
-external::exists(0)
-external::get(0)
-1st
-external::exists(1)
-external::get(1)
-1
-external::exists(2)
-external::get(2)
-3rd
-external::exists(4th)
-external::get(4th)
-4
-INTERNAL
-array(4) {
- [0]=>
- string(3) "1st"
- [1]=>
- int(1)
- [2]=>
- string(3) "3rd"
- ["4th"]=>
- int(4)
-}
-internal::get(0)
-string(3) "1st"
-internal::get(1)
-int(1)
-internal::get(2)
-string(3) "3rd"
-internal::get(4th)
-int(4)
-internal::get(5th)
-
-Notice: Undefined index: 5th in %s on line %d
-NULL
-internal::get(6)
-
-Notice: Undefined offset: 6 in %s on line %d
-NULL
-internal::exists(0)
-internal::get(0)
-string(3) "1st"
-internal::exists(1)
-internal::get(1)
-int(1)
-internal::exists(2)
-internal::get(2)
-string(3) "3rd"
-internal::exists(4th)
-internal::get(4th)
-int(4)
-internal::exists(5th)
-
-Notice: Undefined index: 5th in %s on line %d
-NULL
-internal::exists(6)
-
-Notice: Undefined index: 6 in %s on line %d
-NULL
-internal::exists(0)
-internal::get(0)
-1st
-internal::exists(1)
-internal::get(1)
-1
-internal::exists(2)
-internal::get(2)
-3rd
-internal::exists(4th)
-internal::get(4th)
-4
-Done
+++ /dev/null
---TEST--
-SPL: foreach and iterator
---SKIPIF--
-<?php if (!extension_loaded("spl")) print "skip"; ?>
---FILE--
-<?php
-class c_iter implements spl_forward_assoc {
-
- private $obj;
- private $num = 0;
-
- function __construct($obj) {
- echo __METHOD__ . "\n";
- $this->num = 0;
- $this->obj = $obj;
- }
- function current() {
- echo __METHOD__ . "\n";
- return $this->num;
- }
- function next() {
- echo __METHOD__ . "\n";
- $this->num++;
- }
- function hasMore() {
- $more = $this->num < $this->obj->max;
- echo __METHOD__ . ' = ' .($more ? 'true' : 'false') . "\n";
- return $more;
- }
- function key() {
- echo __METHOD__ . "\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 newIterator() {
- echo __METHOD__ . "\n";
- return new c_iter($this);
- }
-}
-
-$t = new c();
-
-for ($iter = $t->newIterator(); $iter->hasMore(); $iter->next()) {
- echo $iter->current() . "\n";
-}
-
-$a = array(0,1,2);
-foreach($a as $v) {
- echo "array:$v\n";
-}
-
-foreach($t as $v) {
- echo "object:$v\n";
-}
-
-foreach($t as $v) {
- foreach($t as $w) {
- echo "double:$v:$w\n";
- }
-}
-
-foreach($t as $i => $v) {
- echo "object:$i=>$v\n";
-}
-
-print "Done\n";
-?>
---EXPECT--
-c::newIterator
-c_iter::__construct
-c_iter::hasMore = true
-c_iter::current
-0
-c_iter::next
-c_iter::hasMore = true
-c_iter::current
-1
-c_iter::next
-c_iter::hasMore = true
-c_iter::current
-2
-c_iter::next
-c_iter::hasMore = false
-array:0
-array:1
-array:2
-c::newIterator
-c_iter::__construct
-c_iter::hasMore = true
-c_iter::current
-c_iter::key
-object:0
-c_iter::next
-c_iter::hasMore = true
-c_iter::current
-c_iter::key
-object:1
-c_iter::next
-c_iter::hasMore = true
-c_iter::current
-c_iter::key
-object:2
-c_iter::next
-c_iter::hasMore = false
-c::newIterator
-c_iter::__construct
-c_iter::hasMore = true
-c_iter::current
-c_iter::key
-c::newIterator
-c_iter::__construct
-c_iter::hasMore = true
-c_iter::current
-c_iter::key
-double:0:0
-c_iter::next
-c_iter::hasMore = true
-c_iter::current
-c_iter::key
-double:0:1
-c_iter::next
-c_iter::hasMore = true
-c_iter::current
-c_iter::key
-double:0:2
-c_iter::next
-c_iter::hasMore = false
-c_iter::next
-c_iter::hasMore = true
-c_iter::current
-c_iter::key
-c::newIterator
-c_iter::__construct
-c_iter::hasMore = true
-c_iter::current
-c_iter::key
-double:1:0
-c_iter::next
-c_iter::hasMore = true
-c_iter::current
-c_iter::key
-double:1:1
-c_iter::next
-c_iter::hasMore = true
-c_iter::current
-c_iter::key
-double:1:2
-c_iter::next
-c_iter::hasMore = false
-c_iter::next
-c_iter::hasMore = true
-c_iter::current
-c_iter::key
-c::newIterator
-c_iter::__construct
-c_iter::hasMore = true
-c_iter::current
-c_iter::key
-double:2:0
-c_iter::next
-c_iter::hasMore = true
-c_iter::current
-c_iter::key
-double:2:1
-c_iter::next
-c_iter::hasMore = true
-c_iter::current
-c_iter::key
-double:2:2
-c_iter::next
-c_iter::hasMore = false
-c_iter::next
-c_iter::hasMore = false
-c::newIterator
-c_iter::__construct
-c_iter::hasMore = true
-c_iter::current
-c_iter::key
-object:1st=>0
-c_iter::next
-c_iter::hasMore = true
-c_iter::current
-c_iter::key
-object:2nd=>1
-c_iter::next
-c_iter::hasMore = true
-c_iter::current
-c_iter::key
-object:3rd=>2
-c_iter::next
-c_iter::hasMore = false
-Done
+++ /dev/null
---TEST--
-SPL: foreach and break
---SKIPIF--
-<?php if (!extension_loaded("spl")) print "skip"; ?>
---FILE--
-<?php
-class c_iter implements spl_forward_assoc {
-
- 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 hasMore() {
- $more = $this->num < $this->obj->max;
- echo __METHOD__ . ' = ' .($more ? 'true' : 'false') . "\n";
- return $more;
- }
- function key() {
- echo __METHOD__ . "\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 newIterator() {
- echo __METHOD__ . "\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::newIterator
-c_iter::hasMore = true
-c_iter::current
-c_iter::key
-c::newIterator
-c_iter::hasMore = true
-c_iter::current
-c_iter::key
-double:0:0
-c_iter::next
-c_iter::hasMore = true
-c_iter::current
-c_iter::key
-c::newIterator
-c_iter::hasMore = true
-c_iter::current
-c_iter::key
-double:1:0
-c_iter::next
-c_iter::hasMore = true
-c_iter::current
-c_iter::key
-c::newIterator
-c_iter::hasMore = true
-c_iter::current
-c_iter::key
-double:2:0
-c_iter::next
-c_iter::hasMore = false
-Done
+++ /dev/null
---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 hasMore() {
- $more = $this->num < $this->obj->max;
- echo __METHOD__ . ' = ' .($more ? 'true' : 'false') . "\n";
- return $more;
- }
-}
-
-class c implements spl_iterator {
-
- public $max = 4;
-
- function newIterator() {
- 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::newIterator
-c_iter::hasMore = true
-c_iter::current
-continue outer
-c_iter::next
-c_iter::hasMore = true
-c_iter::current
-c::newIterator
-c_iter::hasMore = true
-c_iter::current
-double:1:0
-c_iter::next
-c_iter::hasMore = true
-c_iter::current
-continue inner
-c_iter::next
-c_iter::hasMore = true
-c_iter::current
-break inner
-c_iter::next
-c_iter::hasMore = true
-c_iter::current
-c::newIterator
-c_iter::hasMore = true
-c_iter::current
-double:2:0
-c_iter::next
-c_iter::hasMore = true
-c_iter::current
-continue inner
-c_iter::next
-c_iter::hasMore = true
-c_iter::current
-break inner
-break outer
-Done
+++ /dev/null
---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 hasMore() {
- 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
+++ /dev/null
---TEST--
-SPL: forward
---SKIPIF--
-<?php if (!extension_loaded("spl")) print "skip"; ?>
---FILE--
-<?php
-class c implements spl_forward_assoc {
-
- public $max = 3;
- public $num = 0;
-
- function current() {
- echo __METHOD__ . "\n";
- return $this->num;
- }
- function next() {
- echo __METHOD__ . "\n";
- $this->num++;
- }
- function hasMore() {
- 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 "???";
- }
- }
-}
-
-$i = new c();
-
-$implements = class_implements($i);
-asort($implements);
-$c_info = array(get_class($i) => array('inheits' => class_parents($i), 'implements' => $implements));
-print_r($c_info);
-$methods = get_class_methods("spl_forward_assoc");
-sort($methods);
-print_r($methods);
-$methods = get_class_methods($i);
-sort($methods);
-print_r($methods);
-
-
-echo "1st try\n";
-foreach($i as $w) {
- echo "object:$w\n";
-}
-
-echo "2nd try\n";
-
-foreach($i as $v => $w) {
- echo "object:$v=>$w\n";
-}
-
-echo "3rd try\n";
-$i->num = 0;
-
-foreach($i as $v => $w) {
- echo "object:$v=>$w\n";
-}
-
-print "Done\n";
-?>
---EXPECT--
-Array
-(
- [c] => Array
- (
- [inheits] => Array
- (
- )
-
- [implements] => Array
- (
- [spl_assoc] => spl_assoc
- [spl_forward] => spl_forward
- [spl_forward_assoc] => spl_forward_assoc
- )
-
- )
-
-)
-Array
-(
- [0] => current
- [1] => hasMore
- [2] => key
- [3] => next
-)
-Array
-(
- [0] => current
- [1] => hasMore
- [2] => key
- [3] => next
-)
-1st try
-c::hasMore
-c::current
-c::key
-object:0
-c::next
-c::hasMore
-c::current
-c::key
-object:1
-c::next
-c::hasMore
-c::current
-c::key
-object:2
-c::next
-c::hasMore
-2nd try
-c::hasMore
-3rd try
-c::hasMore
-c::current
-c::key
-object:1st=>0
-c::next
-c::hasMore
-c::current
-c::key
-object:2nd=>1
-c::next
-c::hasMore
-c::current
-c::key
-object:3rd=>2
-c::next
-c::hasMore
-Done
+++ /dev/null
---TEST--
-SPL: sequence
---SKIPIF--
-<?php if (!extension_loaded("spl")) print "skip"; ?>
---FILE--
-<?php
-class c implements spl_iterator {
-
- public $max = 3;
-
- function newIterator() {
- echo __METHOD__ . "\n";
- return new c_iter($this);
- }
-}
-
-class c_iter implements spl_sequence_assoc {
-
- private $obj;
- private $num = 0;
-
- function __construct($obj) {
- $this->obj = $obj;
- }
- function rewind() {
- echo __METHOD__ . "\n";
- $this->num = 0;
- }
- function current() {
- echo __METHOD__ . "\n";
- return $this->num;
- }
- function next() {
- echo __METHOD__ . "\n";
- $this->num++;
- }
- function hasMore() {
- echo __METHOD__ . "\n";
- return $this->num < $this->obj->max;
- }
- function key() {
- echo __METHOD__ . "\n";
- switch($this->num) {
- case 0: return "1st";
- case 1: return "2nd";
- case 2: return "3rd";
- default: return "???";
- }
- }
-}
-
-$t = new c();
-$i = $t->newIterator();
-
-$implements_t = class_implements($t);
-asort($implements_t);
-$implements_i = class_implements($i);
-asort($implements_i);
-
-$c_info = array(get_class($t) => array('inheits' => class_parents($t), 'implements' => $implements_t),
- get_class($i) => array('inheits' => class_parents($i), 'implements' => $implements_i));
-print_r($c_info);
-
-foreach($i as $w) {
- echo "object:$w\n";
-}
-
-foreach($i as $v => $w) {
- echo "object:$v=>$w\n";
-}
-
-print "Done\n";
-?>
---EXPECT--
-c::newIterator
-Array
-(
- [c] => Array
- (
- [inheits] => Array
- (
- )
-
- [implements] => Array
- (
- [spl_iterator] => spl_iterator
- )
-
- )
-
- [c_iter] => Array
- (
- [inheits] => Array
- (
- )
-
- [implements] => Array
- (
- [spl_assoc] => spl_assoc
- [spl_forward] => spl_forward
- [spl_forward_assoc] => spl_forward_assoc
- [spl_sequence] => spl_sequence
- [spl_sequence_assoc] => spl_sequence_assoc
- )
-
- )
-
-)
-c_iter::rewind
-c_iter::hasMore
-c_iter::current
-c_iter::key
-object:0
-c_iter::next
-c_iter::hasMore
-c_iter::current
-c_iter::key
-object:1
-c_iter::next
-c_iter::hasMore
-c_iter::current
-c_iter::key
-object:2
-c_iter::next
-c_iter::hasMore
-c_iter::rewind
-c_iter::hasMore
-c_iter::current
-c_iter::key
-object:1st=>0
-c_iter::next
-c_iter::hasMore
-c_iter::current
-c_iter::key
-object:2nd=>1
-c_iter::next
-c_iter::hasMore
-c_iter::current
-c_iter::key
-object:3rd=>2
-c_iter::next
-c_iter::hasMore
-Done
\ No newline at end of file