From: Etienne Kneuss Date: Sat, 3 May 2008 15:09:24 +0000 (+0000) Subject: Fix #44484 (define SimpleXMLElement::__toString()) X-Git-Tag: RELEASE_2_0_0b1~103 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d0577693da754ef3780a43bc56cf95a47f1b4c3b;p=php Fix #44484 (define SimpleXMLElement::__toString()) --- diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c index 8af240c7b6..223d265a9a 100644 --- a/ext/simplexml/simplexml.c +++ b/ext/simplexml/simplexml.c @@ -1851,6 +1851,23 @@ static int sxe_object_cast(zval *readobj, zval *writeobj, int type, void *extra } /* }}} */ +/* {{{ proto object SimpleXMLElement::__toString() U + Returns the string content */ +SXE_METHOD(__toString) +{ + zval *result; + + ALLOC_INIT_ZVAL(result); + + if (sxe_object_cast(getThis(), result, IS_STRING, NULL TSRMLS_CC) == SUCCESS) { + RETURN_ZVAL(result, 1, 1); + } else { + zval_ptr_dtor(&result); + RETURN_EMPTY_TEXT(); + } +} +/* }}} */ + static int sxe_count_elements(zval *object, long *count TSRMLS_DC) /* {{{ */ { php_sxe_object *sxe; @@ -2494,6 +2511,7 @@ static const zend_function_entry sxe_functions[] = { /* {{{ */ SXE_ME(getName, NULL, ZEND_ACC_PUBLIC) SXE_ME(addChild, NULL, ZEND_ACC_PUBLIC) SXE_ME(addAttribute, NULL, ZEND_ACC_PUBLIC) + SXE_ME(__toString, NULL, ZEND_ACC_PUBLIC) {NULL, NULL, NULL} }; /* }}} */ diff --git a/ext/simplexml/tests/035.phpt b/ext/simplexml/tests/035.phpt new file mode 100644 index 0000000000..962e4dc956 --- /dev/null +++ b/ext/simplexml/tests/035.phpt @@ -0,0 +1,24 @@ +--TEST-- +SimpleXML: __toString +--SKIPIF-- + +--FILE-- + + +

Blah 1

+

Blah 2

+

Blah 3

+ Blah 4 +
+'; +$foo = simplexml_load_string($string); +$p = $foo->bar->p; +echo $p."\n"; +echo $p->__toString()."\n"; +?> +==Done== +--EXPECT-- +Blah 1 +Blah 1 +==Done==