]> granicus.if.org Git - php/commitdiff
trim() should accept objects with __toString() method
authorDmitry Stogov <dmitry@php.net>
Wed, 17 Aug 2005 11:36:32 +0000 (11:36 +0000)
committerDmitry Stogov <dmitry@php.net>
Wed, 17 Aug 2005 11:36:32 +0000 (11:36 +0000)
ext/reflection/tests/005.phpt
ext/simplexml/tests/004.phpt
ext/standard/string.c
tests/classes/tostring.phpt

index f337e44ae684a841c576ef6912269ed6be2f805c..032775b34321f9cbbc494801a87bf2cb1ca09cd9 100755 (executable)
@@ -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===
index 392b1d4981ec38ecfd85955226537e2aab20a3af..82a0d68980c9d18735bd9e7b5f33f80c41ef36ba 100755 (executable)
@@ -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===
index 84f96d80ec99c1f2377ad70941d9a19f2ba8453a..1a614611d23ac9a7370c0a6fa88301e0daedb958 100644 (file)
@@ -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);
                }
        }
 }
index 7253cd4c7bc5881ee4a42303b3aea2feb816b28f..b639183d2f65e267a2efb7fb92868a51a8e379c8 100644 (file)
@@ -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!====