helly Mon Dec 29 17:26:49 2003 EDT Modified files: /php-src/ext/standard formatted_print.c /php-src/tests/classes tostring.phpt Log: Use __tostring() in all printing functions. Index: php-src/ext/standard/formatted_print.c diff -u php-src/ext/standard/formatted_print.c:1.69 php-src/ext/standard/formatted_print.c:1.70 --- php-src/ext/standard/formatted_print.c:1.69 Mon Aug 11 19:16:53 2003 +++ php-src/ext/standard/formatted_print.c Mon Dec 29 17:26:47 2003 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: formatted_print.c,v 1.69 2003/08/11 23:16:53 iliaa Exp $ */ +/* $Id: formatted_print.c,v 1.70 2003/12/29 22:26:47 helly Exp $ */ #include <math.h> /* modf() */ #include "php.h" @@ -622,15 +622,27 @@ PRINTF_DEBUG(("sprintf: format character='%c'\n", format[inpos])); /* now we expect to find a type specifier */ switch (format[inpos]) { - case 's': - convert_to_string_ex(args[argnum]); + case 's': { + zval *var, var_copy; + int use_copy; + + zend_make_printable_zval(*args[argnum], &var_copy, &use_copy); + if (use_copy) { + var = &var_copy; + } else { + var = *args[argnum]; + } php_sprintf_appendstring(&result, &outpos, &size, - Z_STRVAL_PP(args[argnum]), + Z_STRVAL_P(var), width, precision, padding, alignment, - Z_STRLEN_PP(args[argnum]), + Z_STRLEN_P(var), 0, expprec); + if (use_copy) { + zval_dtor(&var_copy); + } break; + } case 'd': convert_to_long_ex(args[argnum]); Index: php-src/tests/classes/tostring.phpt diff -u php-src/tests/classes/tostring.phpt:1.2 php-src/tests/classes/tostring.phpt:1.3 --- php-src/tests/classes/tostring.phpt:1.2 Mon Dec 15 11:59:20 2003 +++ php-src/tests/classes/tostring.phpt Mon Dec 29 17:26:48 2003 @@ -42,6 +42,13 @@ $ar = array(); $ar[$o->__toString()] = "ERROR"; echo $ar[$o]; + +echo "====test8====\n"; +var_dump(trim($o)); +var_dump(trim((string)$o)); + +echo "====test9====\n"; +echo sprintf("%s", $o); ?> ====DONE!==== --EXPECTF-- @@ -51,7 +58,7 @@ ) Notice: Object of class test1 could not be converted to string in %stostring.php on line %d -string(6) "Object" +string(12) "Object id #%d" object(test1)#%d (0) { } ====test2==== @@ -80,4 +87,13 @@ test2::__toString() Warning: Illegal offset type in %stostring.php on line %d +====test8==== + +Notice: Object of class test2 could not be converted to string in %stostring.php on line %d +string(6) "Object" +test2::__toString() +string(9) "Converted" +====test9==== +test2::__toString() +Converted ====DONE!====
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php