com php-src: Fix SXE->string cast for __toString in inh eriting class: Zend/zend.c Zend/zend_operators.c ext/simplexml/simplexml.c

From: Date: Sat, 03 May 2014 09:29:08 +0000
Subject: com php-src: Fix SXE->string cast for __toString in inh eriting class: Zend/zend.c Zend/zend_operators.c ext/simplexml/simplexml.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-77256@lists.php.net to get a copy of this message
Commit: 42d4adabbd5f497ff8117aac44d2b178854e587b Author: Nikita Popov <nikic@php.net> Sat, 3 May 2014 10:49:10 +0200 Parents: 65f488ece3f946d53b12b8c265185a483b079dfb Branches: phpng Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=42d4adabbd5f497ff8117aac44d2b178854e587b Log: 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. Changed paths: M Zend/zend.c M Zend/zend_operators.c M ext/simplexml/simplexml.c Diff: diff --git a/Zend/zend.c b/Zend/zend.c index f4bab50..6706bad 100644 --- a/Zend/zend.c +++ b/Zend/zend.c @@ -247,9 +247,6 @@ again: { TSRMLS_FETCH(); - if (zend_std_cast_object_tostring(expr, expr_copy, IS_STRING TSRMLS_CC) == SUCCESS) { - break; - } if (Z_OBJ_HANDLER_P(expr, cast_object)) { zval val; diff --git a/Zend/zend_operators.c b/Zend/zend_operators.c index 5c79a98..4093a8a 100644 --- a/Zend/zend_operators.c +++ b/Zend/zend_operators.c @@ -921,9 +921,6 @@ try_again: return STR_INIT("Array", sizeof("Array")-1, 0); case IS_OBJECT: { zval tmp; - //???if (zend_std_cast_object_tostring(op, &tmp, IS_STRING TSRMLS_CC) == SUCCESS) { - //??? return Z_STR(tmp); - //???} if (Z_OBJ_HT_P(op)->cast_object) { if (Z_OBJ_HT_P(op)->cast_object(op, &tmp, IS_STRING TSRMLS_CC) == SUCCESS) { return Z_STR(tmp); diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c index 9e04b59..4ee251e 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 */ }

« previous php.cvs (#77256) next »