diff options
| author | Etienne Kneuss <colder@php.net> | 2008-11-06 00:37:13 +0000 |
|---|---|---|
| committer | Etienne Kneuss <colder@php.net> | 2008-11-06 00:37:13 +0000 |
| commit | 27e41ff48cb942bd8102967b5d59080acaa6a161 (patch) | |
| tree | 3bf085e8845b419392e6e0478c41b3dfc47fe23c /ext/simplexml | |
| parent | a912d80adbeee5526b7748c154c18953daf4d88f (diff) | |
| download | php-git-27e41ff48cb942bd8102967b5d59080acaa6a161.tar.gz | |
MFH: Fix #45976 (Move SXE from SPL to SimpleXML)
Diffstat (limited to 'ext/simplexml')
| -rw-r--r-- | ext/simplexml/config.m4 | 2 | ||||
| -rw-r--r-- | ext/simplexml/config.w32 | 2 | ||||
| -rw-r--r-- | ext/simplexml/simplexml.c | 11 | ||||
| -rwxr-xr-x | ext/simplexml/sxe.c | 186 | ||||
| -rwxr-xr-x | ext/simplexml/sxe.h | 39 | ||||
| -rw-r--r-- | ext/simplexml/tests/bug42259.phpt | 49 | ||||
| -rwxr-xr-x | ext/simplexml/tests/sxe_001.phpt | 63 | ||||
| -rwxr-xr-x | ext/simplexml/tests/sxe_002.phpt | 75 | ||||
| -rwxr-xr-x | ext/simplexml/tests/sxe_003.phpt | 77 | ||||
| -rwxr-xr-x | ext/simplexml/tests/sxe_004.phpt | 145 | ||||
| -rwxr-xr-x | ext/simplexml/tests/sxe_005.phpt | 44 |
11 files changed, 683 insertions, 10 deletions
diff --git a/ext/simplexml/config.m4 b/ext/simplexml/config.m4 index 7bc864409e..2145e23d88 100644 --- a/ext/simplexml/config.m4 +++ b/ext/simplexml/config.m4 @@ -17,7 +17,7 @@ if test "$PHP_SIMPLEXML" != "no"; then PHP_SETUP_LIBXML(SIMPLEXML_SHARED_LIBADD, [ AC_DEFINE(HAVE_SIMPLEXML,1,[ ]) - PHP_NEW_EXTENSION(simplexml, simplexml.c, $ext_shared) + PHP_NEW_EXTENSION(simplexml, simplexml.c sxe.c, $ext_shared) PHP_SUBST(SIMPLEXML_SHARED_LIBADD) ], [ AC_MSG_ERROR([xml2-config not found. Please check your libxml2 installation.]) diff --git a/ext/simplexml/config.w32 b/ext/simplexml/config.w32 index a16b842787..52eeb0c6d4 100644 --- a/ext/simplexml/config.w32 +++ b/ext/simplexml/config.w32 @@ -5,7 +5,7 @@ ARG_WITH("simplexml", "Simple XML support", "yes"); if (PHP_SIMPLEXML == "yes" && PHP_LIBXML == "yes" && ADD_EXTENSION_DEP('simplexml', 'libxml')) { - EXTENSION("simplexml", "simplexml.c"); + EXTENSION("simplexml", "simplexml.c sxe.c"); AC_DEFINE("HAVE_SIMPLEXML", 1, "Simple XML support"); if (!PHP_SIMPLEXML_SHARED) { ADD_FLAG("CFLAGS_SIMPLEXML", "/D LIBXML_STATIC"); diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c index 0820b0ea2f..d1912204c8 100644 --- a/ext/simplexml/simplexml.c +++ b/ext/simplexml/simplexml.c @@ -34,9 +34,7 @@ #include "php_simplexml_exports.h" #include "zend_exceptions.h" #include "zend_interfaces.h" -#ifdef HAVE_SPL -#include "ext/spl/spl_sxe.h" -#endif +#include "sxe.h" #define SXE_ELEMENT_BY_NAME 0 @@ -2535,14 +2533,11 @@ PHP_MINIT_FUNCTION(simplexml) sxe_object_handlers.get_class_entry = zend_get_std_object_handlers()->get_class_entry; sxe_object_handlers.get_class_name = zend_get_std_object_handlers()->get_class_name; -#ifdef HAVE_SPL - if (zend_get_module_started("spl") == SUCCESS) { - PHP_MINIT(spl_sxe)(INIT_FUNC_ARGS_PASSTHRU); - } -#endif /* HAVE_SPL */ php_libxml_register_export(sxe_class_entry, simplexml_export_node); + PHP_MINIT(sxe)(INIT_FUNC_ARGS_PASSTHRU); + return SUCCESS; } /* }}} */ diff --git a/ext/simplexml/sxe.c b/ext/simplexml/sxe.c new file mode 100755 index 0000000000..491185350c --- /dev/null +++ b/ext/simplexml/sxe.c @@ -0,0 +1,186 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2008 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Marcus Boerger <helly@php.net> | + +----------------------------------------------------------------------+ + */ + +/* $Id$ */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "php.h" +#include "php_ini.h" +#include "ext/standard/info.h" +#include "zend_interfaces.h" + +#include "ext/spl/php_spl.h" +#include "ext/spl/spl_iterators.h" +#include "sxe.h" + +zend_class_entry *ce_SimpleXMLIterator = NULL; +zend_class_entry *ce_SimpleXMLElement; + +#include "php_simplexml_exports.h" + +/* {{{ proto void SimpleXMLIterator::rewind() + Rewind to first element */ +PHP_METHOD(ce_SimpleXMLIterator, rewind) +{ + php_sxe_iterator iter; + + iter.sxe = php_sxe_fetch_object(getThis() TSRMLS_CC); + ce_SimpleXMLElement->iterator_funcs.funcs->rewind((zend_object_iterator*)&iter TSRMLS_CC); +} +/* }}} */ + +/* {{{ proto bool SimpleXMLIterator::valid() + Check whether iteration is valid */ +PHP_METHOD(ce_SimpleXMLIterator, valid) +{ + php_sxe_object *sxe = php_sxe_fetch_object(getThis() TSRMLS_CC); + + RETURN_BOOL(sxe->iter.data); +} +/* }}} */ + +/* {{{ proto SimpleXMLIterator SimpleXMLIterator::current() + Get current element */ +PHP_METHOD(ce_SimpleXMLIterator, current) +{ + php_sxe_object *sxe = php_sxe_fetch_object(getThis() TSRMLS_CC); + + if (!sxe->iter.data) { + return; /* return NULL */ + } + + RETURN_ZVAL(sxe->iter.data, 1, 0); +} +/* }}} */ + +/* {{{ proto string SimpleXMLIterator::key() + Get name of current child element */ +PHP_METHOD(ce_SimpleXMLIterator, key) +{ + xmlNodePtr curnode; + php_sxe_object *intern; + php_sxe_object *sxe = php_sxe_fetch_object(getThis() TSRMLS_CC); + + if (!sxe->iter.data) { + RETURN_FALSE; + } + + intern = (php_sxe_object *)zend_object_store_get_object(sxe->iter.data TSRMLS_CC); + if (intern != NULL && intern->node != NULL) { + curnode = (xmlNodePtr)((php_libxml_node_ptr *)intern->node)->node; + RETURN_STRINGL((char*)curnode->name, xmlStrlen(curnode->name), 1); + } + + RETURN_FALSE; +} +/* }}} */ + +/* {{{ proto void SimpleXMLIterator::next() + Move to next element */ +PHP_METHOD(ce_SimpleXMLIterator, next) +{ + php_sxe_iterator iter; + + iter.sxe = php_sxe_fetch_object(getThis() TSRMLS_CC); + ce_SimpleXMLElement->iterator_funcs.funcs->move_forward((zend_object_iterator*)&iter TSRMLS_CC); +} +/* }}} */ + +/* {{{ proto bool SimpleXMLIterator::hasChildren() + Check whether element has children (elements) */ +PHP_METHOD(ce_SimpleXMLIterator, hasChildren) +{ + php_sxe_object *sxe = php_sxe_fetch_object(getThis() TSRMLS_CC); + php_sxe_object *child; + xmlNodePtr node; + + if (!sxe->iter.data || sxe->iter.type == SXE_ITER_ATTRLIST) { + RETURN_FALSE; + } + child = php_sxe_fetch_object(sxe->iter.data TSRMLS_CC); + + GET_NODE(child, node); + if (node) { + node = node->children; + } + while (node && node->type != XML_ELEMENT_NODE) { + node = node->next; + } + RETURN_BOOL(node ? 1 : 0); +} +/* }}} */ + +/* {{{ proto SimpleXMLIterator SimpleXMLIterator::getChildren() + Get child element iterator */ +PHP_METHOD(ce_SimpleXMLIterator, getChildren) +{ + php_sxe_object *sxe = php_sxe_fetch_object(getThis() TSRMLS_CC); + + if (!sxe->iter.data || sxe->iter.type == SXE_ITER_ATTRLIST) { + return; /* return NULL */ + } + RETURN_ZVAL(sxe->iter.data, 1, 0); +} + +static const zend_function_entry funcs_SimpleXMLIterator[] = { + PHP_ME(ce_SimpleXMLIterator, rewind, NULL, ZEND_ACC_PUBLIC) + PHP_ME(ce_SimpleXMLIterator, valid, NULL, ZEND_ACC_PUBLIC) + PHP_ME(ce_SimpleXMLIterator, current, NULL, ZEND_ACC_PUBLIC) + PHP_ME(ce_SimpleXMLIterator, key, NULL, ZEND_ACC_PUBLIC) + PHP_ME(ce_SimpleXMLIterator, next, NULL, ZEND_ACC_PUBLIC) + PHP_ME(ce_SimpleXMLIterator, hasChildren, NULL, ZEND_ACC_PUBLIC) + PHP_ME(ce_SimpleXMLIterator, getChildren, NULL, ZEND_ACC_PUBLIC) + {NULL, NULL, NULL} +}; +/* }}} */ + +PHP_MINIT_FUNCTION(sxe) /* {{{ */ +{ + zend_class_entry **pce; + zend_class_entry sxi; + + if (zend_hash_find(CG(class_table), "simplexmlelement", sizeof("SimpleXMLElement"), (void **) &pce) == FAILURE) { + ce_SimpleXMLElement = NULL; + ce_SimpleXMLIterator = NULL; + return SUCCESS; /* SimpleXML must be initialized before */ + } + + ce_SimpleXMLElement = *pce; + + INIT_CLASS_ENTRY_EX(sxi, "SimpleXMLIterator", strlen("SimpleXMLIterator"), funcs_SimpleXMLIterator); + ce_SimpleXMLIterator = zend_register_internal_class_ex(&sxi, ce_SimpleXMLElement, NULL TSRMLS_CC); + ce_SimpleXMLIterator->create_object = ce_SimpleXMLElement->create_object; + + zend_class_implements(ce_SimpleXMLIterator TSRMLS_CC, 1, spl_ce_RecursiveIterator); + zend_class_implements(ce_SimpleXMLIterator TSRMLS_CC, 1, spl_ce_Countable); + + return SUCCESS; +} +/* }}} */ + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: fdm=marker + * vim: noet sw=4 ts=4 + */ diff --git a/ext/simplexml/sxe.h b/ext/simplexml/sxe.h new file mode 100755 index 0000000000..439e451817 --- /dev/null +++ b/ext/simplexml/sxe.h @@ -0,0 +1,39 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2008 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Marcus Boerger <helly@php.net> | + +----------------------------------------------------------------------+ + */ + +/* $Id$ */ + +#ifndef SXE_H +#define SXE_H + +#include "php.h" + +extern zend_class_entry *ce_SimpleXMLIterator; + +PHP_MINIT_FUNCTION(sxe); + +#endif /* SXE_H */ + +/* + * Local Variables: + * c-basic-offset: 4 + * tab-width: 4 + * End: + * vim600: fdm=marker + * vim: noet sw=4 ts=4 + */ diff --git a/ext/simplexml/tests/bug42259.phpt b/ext/simplexml/tests/bug42259.phpt new file mode 100644 index 0000000000..19c02a577a --- /dev/null +++ b/ext/simplexml/tests/bug42259.phpt @@ -0,0 +1,49 @@ +--TEST-- +Bug #42259 (SimpleXMLIterator loses ancestry) +--SKIPIF-- +<?php +if (!extension_loaded('simplexml')) print 'skip'; +if (!extension_loaded("libxml")) print "skip LibXML not present"; +?> +--FILE-- +<?php +$xml =<<<EOF +<xml> + <fieldset1> + <field1/> + <field2/> + </fieldset1> + <fieldset2> + <options> + <option1/> + <option2/> + <option3/> + </options> + <field1/> + <field2/> + </fieldset2> +</xml> +EOF; + +$sxe = new SimpleXMLIterator($xml); +$rit = new RecursiveIteratorIterator($sxe, RecursiveIteratorIterator::LEAVES_ONLY); +foreach ($rit as $child) { + $path = ''; + $ancestry = $child->xpath('ancestor-or-self::*'); + foreach ($ancestry as $ancestor) { + $path .= $ancestor->getName() . '/'; + } + $path = substr($path, 0, strlen($path) - 1); + echo count($ancestry) . ' steps: ' . $path . PHP_EOL; +} +?> +===DONE=== +--EXPECT-- +3 steps: xml/fieldset1/field1 +3 steps: xml/fieldset1/field2 +4 steps: xml/fieldset2/options/option1 +4 steps: xml/fieldset2/options/option2 +4 steps: xml/fieldset2/options/option3 +3 steps: xml/fieldset2/field1 +3 steps: xml/fieldset2/field2 +===DONE=== diff --git a/ext/simplexml/tests/sxe_001.phpt b/ext/simplexml/tests/sxe_001.phpt new file mode 100755 index 0000000000..bb93eea076 --- /dev/null +++ b/ext/simplexml/tests/sxe_001.phpt @@ -0,0 +1,63 @@ +--TEST-- +SPL: SimpleXMLIterator +--SKIPIF-- +<?php +if (!extension_loaded("simplexml")) print "skip SimpleXML not present"; +if (!extension_loaded("libxml")) print "skip LibXML not present"; +?> +--FILE-- +<?php + +$xml =<<<EOF +<?xml version='1.0'?> +<!DOCTYPE sxe SYSTEM "notfound.dtd"> +<sxe id="elem1"> + <elem1 attr1='first'> + <!-- comment --> + <elem2> + <elem3> + <elem4> + <?test processing instruction ?> + </elem4> + </elem3> + </elem2> + </elem1> +</sxe> +EOF; + +var_dump(simplexml_load_string((binary)$xml, 'SimpleXMLIterator')); + +?> +===DONE=== +--EXPECTF-- +object(SimpleXMLIterator)#%d (2) { + ["@attributes"]=> + array(1) { + ["id"]=> + string(5) "elem1" + } + ["elem1"]=> + object(SimpleXMLIterator)#%d (3) { + ["@attributes"]=> + array(1) { + ["attr1"]=> + string(5) "first" + } + ["comment"]=> + object(SimpleXMLIterator)#%d (0) { + } + ["elem2"]=> + object(SimpleXMLIterator)#%d (1) { + ["elem3"]=> + object(SimpleXMLIterator)#%d (1) { + ["elem4"]=> + object(SimpleXMLIterator)#%d (1) { + ["test"]=> + object(SimpleXMLIterator)#%d (0) { + } + } + } + } + } +} +===DONE=== diff --git a/ext/simplexml/tests/sxe_002.phpt b/ext/simplexml/tests/sxe_002.phpt new file mode 100755 index 0000000000..b937b011d0 --- /dev/null +++ b/ext/simplexml/tests/sxe_002.phpt @@ -0,0 +1,75 @@ +--TEST-- +SPL: SimpleXMLIterator and recursion +--SKIPIF-- +<?php +if (!extension_loaded('simplexml')) print 'skip'; +if (!extension_loaded("libxml")) print "skip LibXML not present"; +?> +--FILE-- +<?php + +$xml =<<<EOF +<?xml version='1.0'?> +<!DOCTYPE sxe SYSTEM "notfound.dtd"> +<sxe id="elem1"> + Plain text. + <elem1 attr1='first'> + Bla bla 1. + <!-- comment --> + <elem2> + Here we have some text data. + <elem3> + And here some more. + <elem4> + Wow once again. + </elem4> + </elem3> + </elem2> + </elem1> + <elem11 attr2='second'> + Bla bla 2. + <elem111> + Foo Bar + </elem111> + </elem11> +</sxe> +EOF; + +$sxe = simplexml_load_string((binary)$xml, 'SimpleXMLIterator'); + +foreach(new RecursiveIteratorIterator($sxe, 1) as $name => $data) { + var_dump($name); + var_dump(get_class($data)); + var_dump(trim($data)); +} + +echo "===DUMP===\n"; + +var_dump(get_class($sxe)); +var_dump(trim($sxe->elem1)); + +?> +===DONE=== +--EXPECT-- +string(5) "elem1" +string(17) "SimpleXMLIterator" +string(10) "Bla bla 1." +string(5) "elem2" +string(17) "SimpleXMLIterator" +string(28) "Here we have some text data." +string(5) "elem3" +string(17) "SimpleXMLIterator" +string(19) "And here some more." +string(5) "elem4" +string(17) "SimpleXMLIterator" +string(15) "Wow once again." +string(6) "elem11" +string(17) "SimpleXMLIterator" +string(10) "Bla bla 2." +string(7) "elem111" +string(17) "SimpleXMLIterator" +string(7) "Foo Bar" +===DUMP=== +string(17) "SimpleXMLIterator" +string(10) "Bla bla 1." +===DONE=== diff --git a/ext/simplexml/tests/sxe_003.phpt b/ext/simplexml/tests/sxe_003.phpt new file mode 100755 index 0000000000..58c7523160 --- /dev/null +++ b/ext/simplexml/tests/sxe_003.phpt @@ -0,0 +1,77 @@ +--TEST-- +SPL: SimpleXMLIterator and getChildren() +--SKIPIF-- +<?php +if (!extension_loaded('simplexml')) print 'skip'; +if (!extension_loaded("libxml")) print "skip LibXML not present"; +?> +--FILE-- +<?php + +$xml =<<<EOF +<?xml version='1.0'?> +<!DOCTYPE sxe SYSTEM "notfound.dtd"> +<sxe id="elem1"> + Plain text. + <elem1 attr1='first'> + Bla bla 1. + <!-- comment --> + <elem2> + Here we have some text data. + <elem3> + And here some more. + <elem4> + Wow once again. + </elem4> + </elem3> + </elem2> + </elem1> + <elem11 attr2='second'> + Bla bla 2. + <elem111> + Foo Bar + </elem111> + </elem11> +</sxe> +EOF; + +$sxe = simplexml_load_string((binary)$xml, 'SimpleXMLIterator'); + +foreach($sxe->getChildren() as $name => $data) { + var_dump($name); + var_dump(get_class($data)); + var_dump(trim($data)); +} + +echo "===RESET===\n"; + +for ($sxe->rewind(); $sxe->valid(); $sxe->next()) { + var_dump($sxe->hasChildren()); + var_dump(trim($sxe->key())); + var_dump(trim($sxe->current())); + foreach($sxe->getChildren() as $name => $data) { + var_dump($name); + var_dump(get_class($data)); + var_dump(trim($data)); + } +} + +?> +===DONE=== +--EXPECTF-- + +Warning: Invalid argument supplied for foreach() in %ssxe_003.php on line %d +===RESET=== +bool(true) +string(5) "elem1" +string(10) "Bla bla 1." +string(5) "elem2" +string(17) "SimpleXMLIterator" +string(28) "Here we have some text data." +bool(true) +string(6) "elem11" +string(10) "Bla bla 2." +string(7) "elem111" +string(17) "SimpleXMLIterator" +string(7) "Foo Bar" +===DONE=== diff --git a/ext/simplexml/tests/sxe_004.phpt b/ext/simplexml/tests/sxe_004.phpt new file mode 100755 index 0000000000..20431de8be --- /dev/null +++ b/ext/simplexml/tests/sxe_004.phpt @@ -0,0 +1,145 @@ +--TEST-- +SPL: SimpleXMLIterator and overridden iterator methods() +--SKIPIF-- +<?php +if (!extension_loaded('simplexml')) print 'skip'; +if (!extension_loaded("libxml")) print "skip LibXML not present"; +?> +--FILE-- +<?php + +$xml =<<<EOF +<?xml version='1.0'?> +<!DOCTYPE sxe SYSTEM "notfound.dtd"> +<sxe id="elem1"> + Plain text. + <elem1 attr1='first'> + Bla bla 1. + <!-- comment --> + <elem2> + Here we have some text data. + <elem3> + And here some more. + <elem4> + Wow once again. + </elem4> + </elem3> + </elem2> + </elem1> + <elem11 attr2='second'> + Bla bla 2. + <elem111> + Foo Bar + </elem111> + </elem11> +</sxe> +EOF; + +class SXETest extends SimpleXMLIterator +{ + function rewind() + { + echo __METHOD__ . "\n"; + return parent::rewind(); + } + function valid() + { + echo __METHOD__ . "\n"; + return parent::valid(); + } + function current() + { + echo __METHOD__ . "\n"; + return parent::current(); + } + function key() + { + echo __METHOD__ . "\n"; + return parent::key(); + } + function next() + { + echo __METHOD__ . "\n"; + return parent::next(); + } + function hasChildren() + { + echo __METHOD__ . "\n"; + return parent::hasChildren(); + } + function getChildren() + { + echo __METHOD__ . "\n"; + return parent::getChildren(); + } +} + +$sxe = new SXETest((binary)$xml); +$rit = new RecursiveIteratorIterator($sxe, RecursiveIteratorIterator::SELF_FIRST); + +foreach($rit as $data) { + var_dump(get_class($data)); + var_dump(trim($data)); +} + +?> +===DONE=== +--EXPECTF-- +SXETest::rewind +SXETest::valid +SXETest::hasChildren +SXETest::valid +SXETest::current +string(7) "SXETest" +string(10) "Bla bla 1." +SXETest::getChildren +SXETest::rewind +SXETest::valid +SXETest::hasChildren +SXETest::valid +SXETest::current +string(7) "SXETest" +string(28) "Here we have some text data." +SXETest::getChildren +SXETest::rewind +SXETest::valid +SXETest::hasChildren +SXETest::valid +SXETest::current +string(7) "SXETest" +string(19) "And here some more." +SXETest::getChildren +SXETest::rewind +SXETest::valid +SXETest::hasChildren +SXETest::valid +SXETest::current +string(7) "SXETest" +string(15) "Wow once again." +SXETest::next +SXETest::valid +SXETest::next +SXETest::valid +SXETest::next +SXETest::valid +SXETest::next +SXETest::valid +SXETest::hasChildren +SXETest::valid +SXETest::current +string(7) "SXETest" +string(10) "Bla bla 2." +SXETest::getChildren +SXETest::rewind +SXETest::valid +SXETest::hasChildren +SXETest::valid +SXETest::current +string(7) "SXETest" +string(7) "Foo Bar" +SXETest::next +SXETest::valid +SXETest::next +SXETest::valid +SXETest::valid +===DONE=== diff --git a/ext/simplexml/tests/sxe_005.phpt b/ext/simplexml/tests/sxe_005.phpt new file mode 100755 index 0000000000..183d351166 --- /dev/null +++ b/ext/simplexml/tests/sxe_005.phpt @@ -0,0 +1,44 @@ +--TEST-- +SPL: SimpleXMLIterator and overriden count() +--SKIPIF-- +<?php +if (!extension_loaded('simplexml')) print 'skip'; +if (!extension_loaded("libxml")) print "skip LibXML not present"; +?> +--FILE-- +<?php + +$xml =<<<EOF +<?xml version='1.0'?> +<sxe> + <elem1/> + <elem2/> + <elem2/> +</sxe> +EOF; + +class SXETest extends SimpleXMLIterator +{ + function count() + { + echo __METHOD__ . "\n"; + return parent::count(); + } +} + +$sxe = new SXETest((binary)$xml); + +var_dump(count($sxe)); +var_dump(count($sxe->elem1)); +var_dump(count($sxe->elem2)); + +?> +===DONE=== +--EXPECT-- +SXETest::count +int(3) +SXETest::count +int(1) +SXETest::count +int(2) +===DONE=== |
