php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #52655
Patch bug52655 revision 2015-03-29 07:17 UTC by kalle@php.net

Patch bug52655 for SimpleXML related Bug #52655

Patch version 2015-03-29 07:17 UTC

Return to Bug #52655 | Download this patch
Patch Revisions:

Developer: kalle@php.net

 ext/simplexml/sxe.c               | 47 +++++++++++++++++++++++++++++++++++++++
 ext/simplexml/tests/bug52655.phpt | 30 +++++++++++++++++++++++++
 2 files changed, 77 insertions(+)

diff --git a/ext/simplexml/sxe.c b/ext/simplexml/sxe.c
index c5241a8..ec32662 100644
--- a/ext/simplexml/sxe.c
+++ b/ext/simplexml/sxe.c
@@ -168,10 +168,52 @@ PHP_METHOD(ce_SimpleXMLIterator, getChildren)
 	}
 	RETURN_ZVAL(&sxe->iter.data, 1, 0);
 }
+/* }}} */
+
+/* {{{ proto SimpleXMLIterator SimpleXMLIterator::offsetGet( $offset )
+   Gets a nodes children element iterator */
+PHP_METHOD(ce_SimpleXMLIterator, offsetGet)
+{
+	return;
+}
+/* }}} */
+
+/* {{{ proto void SimpleXMLIterator::offsetSet( $offset, $value )
+   Sets a nodes children */
+PHP_METHOD(ce_SimpleXMLIterator, offsetSet)
+{
+	return;
+}
+/* }}} */
+
+/* {{{ proto void SimpleXMLIterator::offsetSet( $offset )
+   Unsets (deletes) a node */
+PHP_METHOD(ce_SimpleXMLIterator, offsetUnset)
+{
+	return;
+}
+/* }}} */
+
+/* {{{ proto boolean SimpleXMLIterator::offsetExists( $offset )
+   Checks if a specific node exists */
+PHP_METHOD(ce_SimpleXMLIterator, offsetExists)
+{
+	return;
+}
+/* }}} */
 
 /* {{{ arginfo */
 ZEND_BEGIN_ARG_INFO(arginfo_simplexmliterator__void, 0)
 ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO(arginfo_simplexmliterator_offsetget, 0)
+	ZEND_ARG_INFO(0, offset)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO(arginfo_simplexmliterator_offsetset, 0)
+	ZEND_ARG_INFO(0, offset)
+	ZEND_ARG_INFO(0, value)
+ZEND_END_ARG_INFO()
 /* }}} */
 
 static const zend_function_entry funcs_SimpleXMLIterator[] = {
@@ -182,6 +224,10 @@ static const zend_function_entry funcs_SimpleXMLIterator[] = {
 	PHP_ME(ce_SimpleXMLIterator, next,                   arginfo_simplexmliterator__void, ZEND_ACC_PUBLIC)
 	PHP_ME(ce_SimpleXMLIterator, hasChildren,            arginfo_simplexmliterator__void, ZEND_ACC_PUBLIC)
 	PHP_ME(ce_SimpleXMLIterator, getChildren,            arginfo_simplexmliterator__void, ZEND_ACC_PUBLIC)
+	PHP_ME(ce_SimpleXMLIterator, offsetGet,				 arginfo_simplexmliterator_offsetget, ZEND_ACC_PUBLIC)
+	PHP_ME(ce_SimpleXMLIterator, offsetSet,				 arginfo_simplexmliterator_offsetset, ZEND_ACC_PUBLIC)
+	PHP_ME(ce_SimpleXMLIterator, offsetUnset,			 arginfo_simplexmliterator_offsetget, ZEND_ACC_PUBLIC)
+	PHP_ME(ce_SimpleXMLIterator, offsetExists,  		 arginfo_simplexmliterator_offsetget, ZEND_ACC_PUBLIC)
 	{NULL, NULL, NULL}
 };
 /* }}} */
@@ -205,6 +251,7 @@ PHP_MINIT_FUNCTION(sxe) /* {{{ */
 
 	zend_class_implements(ce_SimpleXMLIterator, 1, spl_ce_RecursiveIterator);
 	zend_class_implements(ce_SimpleXMLIterator, 1, spl_ce_Countable);
+	zend_class_implements(ce_SimpleXMLIterator, 1, spl_ce_ArrayAccess);
 
 	return SUCCESS;
 }
diff --git a/ext/simplexml/tests/bug52655.phpt b/ext/simplexml/tests/bug52655.phpt
new file mode 100644
index 0000000..4e6f623
--- /dev/null
+++ b/ext/simplexml/tests/bug52655.phpt
@@ -0,0 +1,30 @@
+--TEST--
+Bug #52655: SimpleXMLIterator supports ArrayAccess without implementing Interface
+--SKIPIF--
+<?php if (!extension_loaded("simplexml")) print "skip"; ?>
+--FILE--
+<?php
+$xml =<<<EOF
+<people>
+   <person name="Rasmus"></person>
+   <person name="Andi"></person>
+   <person name="Zeev"></person>
+</people>
+EOF;
+
+$x = 0;
+$people = new SimpleXMLIterator($xml);
+
+var_dump($people instanceof ArrayAccess);
+
+foreach($people->person as $person) {
+	echo ++$x . ':' . $person['name'] . PHP_EOL;
+}
+?>
+==Done==
+--EXPECT--
+bool(true)
+1:Rasmus
+2:Andi
+3:Zeev
+==Done==
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Nov 22 00:01:30 2024 UTC