From: Dmitry Stogov Date: Wed, 17 Aug 2005 11:36:32 +0000 (+0000) Subject: trim() should accept objects with __toString() method X-Git-Tag: PRE_NEW_OCI8_EXTENSION~199 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3509630024ff5a6e534850072e5c6b974ebce17c;p=php trim() should accept objects with __toString() method --- diff --git a/ext/reflection/tests/005.phpt b/ext/reflection/tests/005.phpt index f337e44ae6..032775b343 100755 --- a/ext/reflection/tests/005.phpt +++ b/ext/reflection/tests/005.phpt @@ -52,3 +52,10 @@ bool(false) bool(false) string(22) "* Comment for A::baz()" ===DONE=== +--UEXPECT-- +unicode(19) "Comment for class A" +unicode(15) "Method A::bla()" +bool(false) +bool(false) +unicode(22) "* Comment for A::baz()" +===DONE=== diff --git a/ext/simplexml/tests/004.phpt b/ext/simplexml/tests/004.phpt index 392b1d4981..82a0d68980 100755 --- a/ext/simplexml/tests/004.phpt +++ b/ext/simplexml/tests/004.phpt @@ -63,3 +63,33 @@ SimpleXMLElement Object ) string(11) "CDATA block" ===DONE=== +--UEXPECT-- +SimpleXMLElement Object +( + [elem1] => SimpleXMLElement Object + ( + [comment] => SimpleXMLElement Object + ( + ) + + [elem2] => SimpleXMLElement Object + ( + [elem3] => SimpleXMLElement Object + ( + [elem4] => SimpleXMLElement Object + ( + [test] => SimpleXMLElement Object + ( + ) + + ) + + ) + + ) + + ) + +) +unicode(11) "CDATA block" +===DONE=== diff --git a/ext/standard/string.c b/ext/standard/string.c index 84f96d80ec..1a614611d2 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -737,30 +737,31 @@ static UChar *php_u_trim(UChar *c, int32_t len, UChar *what, int32_t what_len, z */ static void php_do_trim(INTERNAL_FUNCTION_PARAMETERS, int mode) { - void *str; - int32_t str_len; - zend_uchar str_type; - void *what; - int32_t what_len; - zend_uchar what_type; - int argc = ZEND_NUM_ARGS(); + zval **str, **what; + int argc = ZEND_NUM_ARGS(); - if ( zend_parse_parameters(argc TSRMLS_CC, "T|T", &str, &str_len, &str_type, - &what, &what_len, &what_type) == FAILURE ) { - return; + if (argc < 1 || argc > 2 || zend_get_parameters_ex(argc, &str, &what) == FAILURE) { + WRONG_PARAM_COUNT; } - if ( argc > 1 ) { - if ( str_type == IS_UNICODE ) { - php_u_trim(str, str_len, what, what_len, return_value, mode TSRMLS_CC); + convert_to_text_ex(str); + + if (argc > 1) { + if (Z_TYPE_PP(str) != Z_TYPE_PP(what)) { + zend_error(E_WARNING, "%v() expects parameter 2 to be string (legacy, Unicode, or binary), %s given", + get_active_function_name(TSRMLS_C), + zend_zval_type_name(*what)); + } + if (Z_TYPE_PP(str) == IS_UNICODE) { + php_u_trim(Z_USTRVAL_PP(str), Z_USTRLEN_PP(str), Z_USTRVAL_PP(what), Z_USTRLEN_PP(what), return_value, mode TSRMLS_CC); } else { - php_trim(str, str_len, what, what_len, str_type, return_value, mode TSRMLS_CC); + php_trim(Z_STRVAL_PP(str), Z_STRLEN_PP(str), Z_STRVAL_PP(what), Z_STRLEN_PP(what), Z_TYPE_PP(str), return_value, mode TSRMLS_CC); } } else { - if ( str_type == IS_UNICODE ) { - php_u_trim(str, str_len, NULL, 0, return_value, mode TSRMLS_CC); + if (Z_TYPE_PP(str) == IS_UNICODE) { + php_u_trim(Z_USTRVAL_PP(str), Z_USTRLEN_PP(str), NULL, 0, return_value, mode TSRMLS_CC); } else { - php_trim(str, str_len, NULL, 0, str_type, return_value, mode TSRMLS_CC); + php_trim(Z_STRVAL_PP(str), Z_STRLEN_PP(str), NULL, 0, Z_TYPE_PP(str), return_value, mode TSRMLS_CC); } } } diff --git a/tests/classes/tostring.phpt b/tests/classes/tostring.phpt index 7253cd4c7b..b639183d2f 100644 --- a/tests/classes/tostring.phpt +++ b/tests/classes/tostring.phpt @@ -84,3 +84,36 @@ string(6) "Object" string(1%d) "Object id #%d" ====test9==== Object id #%d====DONE!==== +--UEXPECTF-- +====test1==== +test1 Object +( +) +string(1%d) "Object id #%d" +object(test1)#%d (%d) { +} +====test2==== +test2 Object +( +) +test2::__toString() +Converted +object(test2)#%d (%d) { +} +====test3==== +test2::__toString() +Converted +====test4==== +string:Object id #%d====test5==== +1Object id #%d====test6==== +Object id #%dObject id #2====test7==== +test2::__toString() + +Warning: Illegal offset type in %stostring.php on line %d +====test8==== + +Notice: Object of class test2 to string conversion in %stostring.php on line %d +unicode(6) "Object" +unicode(1%d) "Object id #%d" +====test9==== +Object id #%d====DONE!====