diff options
| author | Xinchen Hui <laruence@php.net> | 2012-08-12 11:50:28 +0800 |
|---|---|---|
| committer | Xinchen Hui <laruence@php.net> | 2012-08-12 11:50:28 +0800 |
| commit | 7b307fb930e6cf328993dee4b060f6f823c39d24 (patch) | |
| tree | 1810b514ba3f2aa08d135ed6d2a51674d5d98fc7 | |
| parent | d4f9bbfae248687c1aa68370564b14544eb4eafd (diff) | |
| download | php-git-7b307fb930e6cf328993dee4b060f6f823c39d24.tar.gz | |
Fixed bug #62328 (implementing __toString and a cast to string fails)
__toString should has a high priority
| -rw-r--r-- | NEWS | 2 | ||||
| -rw-r--r-- | Zend/zend.c | 9 | ||||
| -rw-r--r-- | ext/xml/tests/bug62328.phpt | 21 |
3 files changed, 26 insertions, 6 deletions
@@ -3,6 +3,8 @@ PHP NEWS ?? ??? 2012, PHP 5.4.7 - Core: + . Fixed bug #62328 (implementing __toString and a cast to string fails) + (Laruence) . Fixed bug #62725 (Calling exit() in a shutdown function does not return the exit value). (Laruence) . Fixed bug #51363 (Fatal error raised by var_export() not caught by error diff --git a/Zend/zend.c b/Zend/zend.c index 18c4f11604..09338e7f83 100644 --- a/Zend/zend.c +++ b/Zend/zend.c @@ -258,6 +258,9 @@ ZEND_API void zend_make_printable_zval(zval *expr, zval *expr_copy, int *use_cop { 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; @@ -270,12 +273,6 @@ ZEND_API void zend_make_printable_zval(zval *expr, zval *expr_copy, int *use_cop } zval_ptr_dtor(&val); } - /* Standard PHP objects */ - if (Z_OBJ_HT_P(expr) == &std_object_handlers || !Z_OBJ_HANDLER_P(expr, cast_object)) { - if (zend_std_cast_object_tostring(expr, expr_copy, IS_STRING TSRMLS_CC) == SUCCESS) { - break; - } - } if (!Z_OBJ_HANDLER_P(expr, cast_object) && Z_OBJ_HANDLER_P(expr, get)) { zval *z = Z_OBJ_HANDLER_P(expr, get)(expr TSRMLS_CC); diff --git a/ext/xml/tests/bug62328.phpt b/ext/xml/tests/bug62328.phpt new file mode 100644 index 0000000000..e4c3c59d37 --- /dev/null +++ b/ext/xml/tests/bug62328.phpt @@ -0,0 +1,21 @@ +--TEST-- +Bug #62328 (implementing __toString and a cast to string fails) +--SKIPIF-- +<?php +require_once("skipif.inc"); +?> +--FILE-- +<?php +class UberSimpleXML extends SimpleXMLElement { + public function __toString() { + return 'stringification'; + } +} + +$xml = new UberSimpleXML('<xml/>'); + +var_dump((string) $xml); +var_dump($xml->__toString()); +--EXPECT-- +string(15) "stringification" +string(15) "stringification" |
