diff options
author | Nikita Popov <nikic@php.net> | 2014-05-03 10:49:10 +0200 |
---|---|---|
committer | Nikita Popov <nikic@php.net> | 2014-05-03 11:29:08 +0200 |
commit | 42d4adabbd5f497ff8117aac44d2b178854e587b (patch) | |
tree | 1b58bc25ab7ca85e177bb93a0431095accc1ec08 /ext/simplexml | |
parent | 65f488ece3f946d53b12b8c265185a483b079dfb (diff) | |
download | php-git-42d4adabbd5f497ff8117aac44d2b178854e587b.tar.gz |
Fix SXE->string cast for __toString in inheriting class
This issue was originally hacked around in zend_make_printable_zval.
I've now moved the overridden __toString() handling into the SXE
cast_object handler, so everything invoking that handler
(zend_make_printable_zval, convert_to_string, zval_get_string,
and various other more obscure usages) see the same behavior.
Diffstat (limited to 'ext/simplexml')
-rw-r--r-- | ext/simplexml/simplexml.c | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c index 9e04b592b7..4ee251ecf8 100644 --- a/ext/simplexml/simplexml.c +++ b/ext/simplexml/simplexml.c @@ -1774,7 +1774,7 @@ static int cast_object(zval *object, int type, char *contents TSRMLS_DC) /* {{{ sxe_object_cast() */ -static int sxe_object_cast(zval *readobj, zval *writeobj, int type TSRMLS_DC) +static int sxe_object_cast_ex(zval *readobj, zval *writeobj, int type TSRMLS_DC) { php_sxe_object *sxe; xmlChar *contents = NULL; @@ -1826,13 +1826,25 @@ static int sxe_object_cast(zval *readobj, zval *writeobj, int type TSRMLS_DC) } /* }}} */ +/* Variant of sxe_object_cast_ex that handles overwritten __toString() method */ +static int sxe_object_cast(zval *readobj, zval *writeobj, int type TSRMLS_DC) +{ + if (type == IS_STRING + && zend_std_cast_object_tostring(readobj, writeobj, IS_STRING TSRMLS_CC) == SUCCESS + ) { + return SUCCESS; + } + + return sxe_object_cast_ex(readobj, writeobj, type TSRMLS_CC); +} + /* {{{ proto object SimpleXMLElement::__toString() U Returns the string content */ SXE_METHOD(__toString) { zval result; - if (sxe_object_cast(getThis(), &result, IS_STRING TSRMLS_CC) == SUCCESS) { + if (sxe_object_cast_ex(getThis(), &result, IS_STRING TSRMLS_CC) == SUCCESS) { RETURN_ZVAL(&result, 0, 0); } else { zval_ptr_dtor(&result); @@ -1909,7 +1921,7 @@ SXE_METHOD(count) static zval *sxe_get_value(zval *z, zval *rv TSRMLS_DC) /* {{{ */ { - if (sxe_object_cast(z, rv, IS_STRING TSRMLS_CC) == FAILURE) { + if (sxe_object_cast_ex(z, rv, IS_STRING TSRMLS_CC) == FAILURE) { zend_error(E_ERROR, "Unable to cast node to string"); /* FIXME: Should not be fatal */ } |