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]);
$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--
)
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====
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!====