From: Máté Kocsis Date: Fri, 15 Nov 2019 19:31:19 +0000 (+0100) Subject: Only accept string as the format parameter of *printf() functions X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b2dc833c1a243ba50ab76a0212f071bd8d1f7c04;p=php Only accept string as the format parameter of *printf() functions --- diff --git a/ext/standard/formatted_print.c b/ext/standard/formatted_print.c index a5acaeea9b..c8d912793a 100644 --- a/ext/standard/formatted_print.c +++ b/ext/standard/formatted_print.c @@ -392,22 +392,15 @@ php_sprintf_getnumber(char **buffer, size_t *len) * - 0 or more: ArgumentCountError is thrown */ static zend_string * -php_formatted_print(zval *z_format, zval *args, int argc, int nb_additional_parameters) +php_formatted_print(char *format, size_t format_len, zval *args, int argc, int nb_additional_parameters) { size_t size = 240, outpos = 0; int alignment, currarg, adjusting, argnum, width, precision; - char *format, *temppos, padding; + char *temppos, padding; zend_string *result; int always_sign; - size_t format_len; int bad_arg_number = 0; - if (!try_convert_to_string(z_format)) { - return NULL; - } - - format = Z_STRVAL_P(z_format); - format_len = Z_STRLEN_P(z_format); result = zend_string_alloc(size, 0); currarg = 0; @@ -680,15 +673,17 @@ php_formatted_print_get_array(zval *array, int *argc) PHP_FUNCTION(user_sprintf) { zend_string *result; - zval *format, *args; + char *format; + size_t format_len; + zval *args; int argc; ZEND_PARSE_PARAMETERS_START(1, -1) - Z_PARAM_ZVAL(format) + Z_PARAM_STRING(format, format_len) Z_PARAM_VARIADIC('*', args, argc) ZEND_PARSE_PARAMETERS_END(); - result = php_formatted_print(format, args, argc, 1); + result = php_formatted_print(format, format_len, args, argc, 1); if (result == NULL) { return; } @@ -701,17 +696,19 @@ PHP_FUNCTION(user_sprintf) PHP_FUNCTION(vsprintf) { zend_string *result; - zval *format, *array, *args; + char *format; + size_t format_len; + zval *array, *args; int argc; ZEND_PARSE_PARAMETERS_START(2, 2) - Z_PARAM_ZVAL(format) + Z_PARAM_STRING(format, format_len) Z_PARAM_ZVAL(array) ZEND_PARSE_PARAMETERS_END(); args = php_formatted_print_get_array(array, &argc); - result = php_formatted_print(format, args, argc, -1); + result = php_formatted_print(format, format_len, args, argc, -1); efree(args); if (result == NULL) { return; @@ -726,15 +723,17 @@ PHP_FUNCTION(user_printf) { zend_string *result; size_t rlen; - zval *format, *args; + char *format; + size_t format_len; + zval *args; int argc; ZEND_PARSE_PARAMETERS_START(1, -1) - Z_PARAM_ZVAL(format) + Z_PARAM_STRING(format, format_len) Z_PARAM_VARIADIC('*', args, argc) ZEND_PARSE_PARAMETERS_END(); - result = php_formatted_print(format, args, argc, 1); + result = php_formatted_print(format, format_len, args, argc, 1); if (result == NULL) { return; } @@ -750,17 +749,19 @@ PHP_FUNCTION(vprintf) { zend_string *result; size_t rlen; - zval *format, *array, *args; + char *format; + size_t format_len; + zval *array, *args; int argc; ZEND_PARSE_PARAMETERS_START(2, 2) - Z_PARAM_ZVAL(format) + Z_PARAM_STRING(format, format_len) Z_PARAM_ZVAL(array) ZEND_PARSE_PARAMETERS_END(); args = php_formatted_print_get_array(array, &argc); - result = php_formatted_print(format, args, argc, -1); + result = php_formatted_print(format, format_len, args, argc, -1); efree(args); if (result == NULL) { return; @@ -776,7 +777,9 @@ PHP_FUNCTION(vprintf) PHP_FUNCTION(fprintf) { php_stream *stream; - zval *arg1, *format, *args; + char *format; + size_t format_len; + zval *arg1, *args; int argc; zend_string *result; @@ -786,13 +789,13 @@ PHP_FUNCTION(fprintf) ZEND_PARSE_PARAMETERS_START(2, -1) Z_PARAM_RESOURCE(arg1) - Z_PARAM_ZVAL(format) + Z_PARAM_STRING(format, format_len) Z_PARAM_VARIADIC('*', args, argc) ZEND_PARSE_PARAMETERS_END(); php_stream_from_zval(stream, arg1); - result = php_formatted_print(format, args, argc, 2); + result = php_formatted_print(format, format_len, args, argc, 2); if (result == NULL) { return; } @@ -809,7 +812,9 @@ PHP_FUNCTION(fprintf) PHP_FUNCTION(vfprintf) { php_stream *stream; - zval *arg1, *format, *array, *args; + char *format; + size_t format_len; + zval *arg1, *array, *args; int argc; zend_string *result; @@ -819,7 +824,7 @@ PHP_FUNCTION(vfprintf) ZEND_PARSE_PARAMETERS_START(3, 3) Z_PARAM_RESOURCE(arg1) - Z_PARAM_ZVAL(format) + Z_PARAM_STRING(format, format_len) Z_PARAM_ZVAL(array) ZEND_PARSE_PARAMETERS_END(); @@ -827,7 +832,7 @@ PHP_FUNCTION(vfprintf) args = php_formatted_print_get_array(array, &argc); - result = php_formatted_print(format, args, argc, -1); + result = php_formatted_print(format, format_len, args, argc, -1); efree(args); if (result == NULL) { return; diff --git a/ext/standard/tests/file/fscanf_variation10.phpt b/ext/standard/tests/file/fscanf_variation10.phpt index 158c6579d9..2b98ec31d3 100644 --- a/ext/standard/tests/file/fscanf_variation10.phpt +++ b/ext/standard/tests/file/fscanf_variation10.phpt @@ -42,7 +42,7 @@ $counter = 1; // writing to the file foreach($resource_types as $value) { - @fprintf($file_handle, $value); + @fprintf($file_handle, "%s", $value); @fprintf($file_handle, "\n"); } // closing the file diff --git a/ext/standard/tests/file/fscanf_variation11.phpt b/ext/standard/tests/file/fscanf_variation11.phpt index 97dfa810a2..208eda05ba 100644 --- a/ext/standard/tests/file/fscanf_variation11.phpt +++ b/ext/standard/tests/file/fscanf_variation11.phpt @@ -47,7 +47,7 @@ $counter = 1; // writing to the file foreach($array_types as $value) { - @fprintf($file_handle, $value); + @fprintf($file_handle, "%s", $value); @fprintf($file_handle, "\n"); } // closing the file diff --git a/ext/standard/tests/file/fscanf_variation16.phpt b/ext/standard/tests/file/fscanf_variation16.phpt index a9fd0cf84d..fd71de7b25 100644 --- a/ext/standard/tests/file/fscanf_variation16.phpt +++ b/ext/standard/tests/file/fscanf_variation16.phpt @@ -41,7 +41,7 @@ $counter = 1; // writing to the file foreach($resource_types as $value) { - @fprintf($file_handle, $value); + @fprintf($file_handle, "%s", $value); @fprintf($file_handle, "\n"); } // closing the file diff --git a/ext/standard/tests/file/fscanf_variation17.phpt b/ext/standard/tests/file/fscanf_variation17.phpt index 4e976c7cb4..276246535b 100644 --- a/ext/standard/tests/file/fscanf_variation17.phpt +++ b/ext/standard/tests/file/fscanf_variation17.phpt @@ -46,7 +46,7 @@ $counter = 1; // writing to the file foreach($array_types as $value) { - @fprintf($file_handle, $value); + @fprintf($file_handle, "%s", $value); @fprintf($file_handle, "\n"); } // closing the file diff --git a/ext/standard/tests/file/fscanf_variation22.phpt b/ext/standard/tests/file/fscanf_variation22.phpt index adb848a908..f65578e32d 100644 --- a/ext/standard/tests/file/fscanf_variation22.phpt +++ b/ext/standard/tests/file/fscanf_variation22.phpt @@ -41,7 +41,7 @@ $counter = 1; // writing to the file foreach($resource_types as $value) { - @fprintf($file_handle, $value); + @fprintf($file_handle, "%s", $value); @fprintf($file_handle, "\n"); } // closing the file diff --git a/ext/standard/tests/file/fscanf_variation23.phpt b/ext/standard/tests/file/fscanf_variation23.phpt index c1b9ca6580..b90dfde6ff 100644 --- a/ext/standard/tests/file/fscanf_variation23.phpt +++ b/ext/standard/tests/file/fscanf_variation23.phpt @@ -46,7 +46,7 @@ $counter = 1; // writing to the file foreach($array_types as $value) { - @fprintf($file_handle, $value); + @fprintf($file_handle, "%s", $value); @fprintf($file_handle, "\n"); } // closing the file diff --git a/ext/standard/tests/file/fscanf_variation29.phpt b/ext/standard/tests/file/fscanf_variation29.phpt index 1db4973290..ec518a0964 100644 --- a/ext/standard/tests/file/fscanf_variation29.phpt +++ b/ext/standard/tests/file/fscanf_variation29.phpt @@ -42,7 +42,7 @@ $counter = 1; // writing to the file foreach($resource_types as $value) { - @fprintf($file_handle, $value); + @fprintf($file_handle, "%s", $value); @fprintf($file_handle, "\n"); } // closing the file diff --git a/ext/standard/tests/file/fscanf_variation30.phpt b/ext/standard/tests/file/fscanf_variation30.phpt index c01f5aa2e6..8db09ba5db 100644 --- a/ext/standard/tests/file/fscanf_variation30.phpt +++ b/ext/standard/tests/file/fscanf_variation30.phpt @@ -47,7 +47,7 @@ $counter = 1; // writing to the file foreach($array_types as $value) { - @fprintf($file_handle, $value); + @fprintf($file_handle, "%s", $value); @fprintf($file_handle, "\n"); } // closing the file diff --git a/ext/standard/tests/file/fscanf_variation35.phpt b/ext/standard/tests/file/fscanf_variation35.phpt index 445280c2fd..5211e8bc9c 100644 --- a/ext/standard/tests/file/fscanf_variation35.phpt +++ b/ext/standard/tests/file/fscanf_variation35.phpt @@ -37,7 +37,7 @@ $counter = 1; // writing to the file foreach($resource_types as $value) { - @fprintf($file_handle, $value); + @fprintf($file_handle, "%s", $value); @fprintf($file_handle, "\n"); } // closing the file diff --git a/ext/standard/tests/file/fscanf_variation36.phpt b/ext/standard/tests/file/fscanf_variation36.phpt index 9eb617077d..230bf387a9 100644 --- a/ext/standard/tests/file/fscanf_variation36.phpt +++ b/ext/standard/tests/file/fscanf_variation36.phpt @@ -42,7 +42,7 @@ $counter = 1; // writing to the file foreach($array_types as $value) { - @fprintf($file_handle, $value); + @fprintf($file_handle, "%s", $value); @fprintf($file_handle, "\n"); } // closing the file diff --git a/ext/standard/tests/file/fscanf_variation4.phpt b/ext/standard/tests/file/fscanf_variation4.phpt index b802a90da3..57906f4fc3 100644 --- a/ext/standard/tests/file/fscanf_variation4.phpt +++ b/ext/standard/tests/file/fscanf_variation4.phpt @@ -38,7 +38,7 @@ $counter = 1; // writing to the file foreach($resource_types as $value) { - @fprintf($file_handle, $value); + @fprintf($file_handle, "%s", $value); @fprintf($file_handle, "\n"); } // closing the file diff --git a/ext/standard/tests/file/fscanf_variation41.phpt b/ext/standard/tests/file/fscanf_variation41.phpt index 487954097f..e9bfb5ac91 100644 --- a/ext/standard/tests/file/fscanf_variation41.phpt +++ b/ext/standard/tests/file/fscanf_variation41.phpt @@ -37,7 +37,7 @@ $counter = 1; // writing to the file foreach($resource_types as $value) { - @fprintf($file_handle, $value); + @fprintf($file_handle, "%s", $value); @fprintf($file_handle, "\n"); } // closing the file diff --git a/ext/standard/tests/file/fscanf_variation42.phpt b/ext/standard/tests/file/fscanf_variation42.phpt index 45cf3696b5..a33b5ea806 100644 --- a/ext/standard/tests/file/fscanf_variation42.phpt +++ b/ext/standard/tests/file/fscanf_variation42.phpt @@ -42,7 +42,7 @@ $counter = 1; // writing to the file foreach($array_types as $value) { - @fprintf($file_handle, $value); + @fprintf($file_handle, "%s", $value); @fprintf($file_handle, "\n"); } // closing the file diff --git a/ext/standard/tests/file/fscanf_variation47.phpt b/ext/standard/tests/file/fscanf_variation47.phpt index 6217b32b61..ecc0543bf6 100644 --- a/ext/standard/tests/file/fscanf_variation47.phpt +++ b/ext/standard/tests/file/fscanf_variation47.phpt @@ -37,7 +37,7 @@ $counter = 1; // writing to the file foreach($resource_types as $value) { - @fprintf($file_handle, $value); + @fprintf($file_handle, "%s", $value); @fprintf($file_handle, "\n"); } // closing the file diff --git a/ext/standard/tests/file/fscanf_variation48.phpt b/ext/standard/tests/file/fscanf_variation48.phpt index 355d5cf187..9b7c874a49 100644 --- a/ext/standard/tests/file/fscanf_variation48.phpt +++ b/ext/standard/tests/file/fscanf_variation48.phpt @@ -42,7 +42,7 @@ $counter = 1; // writing to the file foreach($array_types as $value) { - @fprintf($file_handle, $value); + @fprintf($file_handle, "%s", $value); @fprintf($file_handle, "\n"); } // closing the file diff --git a/ext/standard/tests/file/fscanf_variation5.phpt b/ext/standard/tests/file/fscanf_variation5.phpt index 714a54b912..a9b92b2f86 100644 --- a/ext/standard/tests/file/fscanf_variation5.phpt +++ b/ext/standard/tests/file/fscanf_variation5.phpt @@ -42,7 +42,7 @@ $counter = 1; // writing to the file foreach($array_types as $value) { - @fprintf($file_handle, $value); + @fprintf($file_handle, "%s", $value); @fprintf($file_handle, "\n"); } // closing the file diff --git a/ext/standard/tests/strings/printf_variation1.phpt b/ext/standard/tests/strings/printf_variation1.phpt index 0884a2ff71..4ec032f9ce 100644 --- a/ext/standard/tests/strings/printf_variation1.phpt +++ b/ext/standard/tests/strings/printf_variation1.phpt @@ -89,19 +89,31 @@ foreach($values as $value) { echo "\n-- Iteration $count --\n"; // with default argument - $result = printf($value); - echo "\n"; - var_dump($result); + try { + $result = printf($value); + echo "\n"; + var_dump($result); + } catch (TypeError $exception) { + echo $exception->getMessage() . "\n"; + } // with two arguments - $result = printf($value, $arg1); - echo "\n"; - var_dump($result); + try { + $result = printf($value, $arg1); + echo "\n"; + var_dump($result); + } catch (TypeError $exception) { + echo $exception->getMessage() . "\n"; + } // with three arguments - $result = printf($value, $arg1, $arg2); - echo "\n"; - var_dump($result); + try { + $result = printf($value, $arg1, $arg2); + echo "\n"; + var_dump($result); + } catch (TypeError $exception) { + echo $exception->getMessage() . "\n"; + } $count++; }; @@ -186,74 +198,29 @@ int(3) int(3) -- Iteration 10 -- - -Warning: Array to string conversion in %s on line %d -Array -int(5) - -Warning: Array to string conversion in %s on line %d -Array -int(5) - -Warning: Array to string conversion in %s on line %d -Array -int(5) +printf() expects parameter 1 to be string, array given +printf() expects parameter 1 to be string, array given +printf() expects parameter 1 to be string, array given -- Iteration 11 -- - -Warning: Array to string conversion in %s on line %d -Array -int(5) - -Warning: Array to string conversion in %s on line %d -Array -int(5) - -Warning: Array to string conversion in %s on line %d -Array -int(5) +printf() expects parameter 1 to be string, array given +printf() expects parameter 1 to be string, array given +printf() expects parameter 1 to be string, array given -- Iteration 12 -- - -Warning: Array to string conversion in %s on line %d -Array -int(5) - -Warning: Array to string conversion in %s on line %d -Array -int(5) - -Warning: Array to string conversion in %s on line %d -Array -int(5) +printf() expects parameter 1 to be string, array given +printf() expects parameter 1 to be string, array given +printf() expects parameter 1 to be string, array given -- Iteration 13 -- - -Warning: Array to string conversion in %s on line %d -Array -int(5) - -Warning: Array to string conversion in %s on line %d -Array -int(5) - -Warning: Array to string conversion in %s on line %d -Array -int(5) +printf() expects parameter 1 to be string, array given +printf() expects parameter 1 to be string, array given +printf() expects parameter 1 to be string, array given -- Iteration 14 -- - -Warning: Array to string conversion in %s on line %d -Array -int(5) - -Warning: Array to string conversion in %s on line %d -Array -int(5) - -Warning: Array to string conversion in %s on line %d -Array -int(5) +printf() expects parameter 1 to be string, array given +printf() expects parameter 1 to be string, array given +printf() expects parameter 1 to be string, array given -- Iteration 15 -- @@ -344,9 +311,6 @@ int(0) int(0) -- Iteration 26 -- -Resource id #%d -int(%d) -Resource id #%d -int(%d) -Resource id #%d -int(%d) +printf() expects parameter 1 to be string, resource given +printf() expects parameter 1 to be string, resource given +printf() expects parameter 1 to be string, resource given diff --git a/ext/standard/tests/strings/sprintf_variation1.phpt b/ext/standard/tests/strings/sprintf_variation1.phpt index 33320b9f1c..f30cf5182e 100644 --- a/ext/standard/tests/strings/sprintf_variation1.phpt +++ b/ext/standard/tests/strings/sprintf_variation1.phpt @@ -89,16 +89,28 @@ foreach($values as $value) { echo "\n-- Iteration $count --\n"; // with default argument - var_dump( sprintf($value) ); + try { + var_dump(sprintf($value)); + } catch (TypeError $exception) { + echo $exception->getMessage() . "\n"; + } // with two arguments - var_dump( sprintf($value, $arg1) ); + try { + var_dump(sprintf($value, $arg1)); + } catch (TypeError $exception) { + echo $exception->getMessage() . "\n"; + } // with three arguments - var_dump( sprintf($value, $arg1, $arg2) ); + try { + var_dump(sprintf($value, $arg1, $arg2)); + } catch (TypeError $exception) { + echo $exception->getMessage() . "\n"; + } $count++; -}; +} // close the resource fclose($file_handle); @@ -154,59 +166,29 @@ string(3) "0.5" string(3) "0.5" -- Iteration 10 -- - -Warning: Array to string conversion in %s on line %d -string(5) "Array" - -Warning: Array to string conversion in %s on line %d -string(5) "Array" - -Warning: Array to string conversion in %s on line %d -string(5) "Array" +sprintf() expects parameter 1 to be string, array given +sprintf() expects parameter 1 to be string, array given +sprintf() expects parameter 1 to be string, array given -- Iteration 11 -- - -Warning: Array to string conversion in %s on line %d -string(5) "Array" - -Warning: Array to string conversion in %s on line %d -string(5) "Array" - -Warning: Array to string conversion in %s on line %d -string(5) "Array" +sprintf() expects parameter 1 to be string, array given +sprintf() expects parameter 1 to be string, array given +sprintf() expects parameter 1 to be string, array given -- Iteration 12 -- - -Warning: Array to string conversion in %s on line %d -string(5) "Array" - -Warning: Array to string conversion in %s on line %d -string(5) "Array" - -Warning: Array to string conversion in %s on line %d -string(5) "Array" +sprintf() expects parameter 1 to be string, array given +sprintf() expects parameter 1 to be string, array given +sprintf() expects parameter 1 to be string, array given -- Iteration 13 -- - -Warning: Array to string conversion in %s on line %d -string(5) "Array" - -Warning: Array to string conversion in %s on line %d -string(5) "Array" - -Warning: Array to string conversion in %s on line %d -string(5) "Array" +sprintf() expects parameter 1 to be string, array given +sprintf() expects parameter 1 to be string, array given +sprintf() expects parameter 1 to be string, array given -- Iteration 14 -- - -Warning: Array to string conversion in %s on line %d -string(5) "Array" - -Warning: Array to string conversion in %s on line %d -string(5) "Array" - -Warning: Array to string conversion in %s on line %d -string(5) "Array" +sprintf() expects parameter 1 to be string, array given +sprintf() expects parameter 1 to be string, array given +sprintf() expects parameter 1 to be string, array given -- Iteration 15 -- string(0) "" @@ -264,7 +246,7 @@ string(0) "" string(0) "" -- Iteration 26 -- -string(%d) "Resource id #%d" -string(%d) "Resource id #%d" -string(%d) "Resource id #%d" +sprintf() expects parameter 1 to be string, resource given +sprintf() expects parameter 1 to be string, resource given +sprintf() expects parameter 1 to be string, resource given Done diff --git a/ext/standard/tests/strings/vfprintf_error3.phpt b/ext/standard/tests/strings/vfprintf_error3.phpt index 06103878a6..0496d9b19c 100644 --- a/ext/standard/tests/strings/vfprintf_error3.phpt +++ b/ext/standard/tests/strings/vfprintf_error3.phpt @@ -17,12 +17,11 @@ $file = 'vfprintf_error3.txt'; $fp = fopen( $file, "a+" ); echo "\n-- Testing vfprintf() function with wrong variable types as argument --\n"; -var_dump( vfprintf( $fp, array( 'foo %d', 'bar %s' ), 3.55552 ) ); - -rewind( $fp ); -var_dump( stream_get_contents( $fp ) ); -ftruncate( $fp, 0 ); -rewind( $fp ); +try { + vfprintf($fp, array( 'foo %d', 'bar %s' ), 3.55552); +} catch (TypeError $exception) { + echo $exception->getMessage() . "\n"; +} var_dump( vfprintf( $fp, "Foo %y fake", "not available" ) ); @@ -42,11 +41,8 @@ $file = 'vfprintf_error3.txt'; unlink( $file ); ?> ---EXPECTF-- +--EXPECT-- -- Testing vfprintf() function with wrong variable types as argument -- - -Warning: Array to string conversion in %s on line %d -int(5) -string(5) "Array" +vfprintf() expects parameter 2 to be string, array given int(9) string(9) "Foo fake" diff --git a/ext/standard/tests/strings/vfprintf_variation20.phpt b/ext/standard/tests/strings/vfprintf_variation20.phpt index c831674bcd..17426c7af7 100644 --- a/ext/standard/tests/strings/vfprintf_variation20.phpt +++ b/ext/standard/tests/strings/vfprintf_variation20.phpt @@ -92,8 +92,13 @@ fprintf($fp, "\n*** Testing vprintf() with with unexpected values for format arg $counter = 1; foreach( $values as $value ) { - fprintf( $fp, "\n-- Iteration %d --\n",$counter); - vfprintf($fp, $value, $args); + fprintf($fp, "\n-- Iteration %d --\n", $counter); + + try { + vfprintf($fp, $value, $args); + } catch (TypeError $exception) { + fprintf($fp, "%s\n", $exception->getMessage()); + } $counter++; } @@ -107,16 +112,6 @@ unlink($data_file); --EXPECTF-- *** Testing vfprintf() : with unexpected values for format argument *** -Warning: Array to string conversion in %s on line %d - -Warning: Array to string conversion in %s on line %d - -Warning: Array to string conversion in %s on line %d - -Warning: Array to string conversion in %s on line %d - -Warning: Array to string conversion in %s on line %d - *** Testing vprintf() with with unexpected values for format argument *** -- Iteration 1 -- @@ -138,15 +133,20 @@ Warning: Array to string conversion in %s on line %d -- Iteration 9 -- 0.5 -- Iteration 10 -- -Array +vfprintf() expects parameter 2 to be string, array given + -- Iteration 11 -- -Array +vfprintf() expects parameter 2 to be string, array given + -- Iteration 12 -- -Array +vfprintf() expects parameter 2 to be string, array given + -- Iteration 13 -- -Array +vfprintf() expects parameter 2 to be string, array given + -- Iteration 14 -- -Array +vfprintf() expects parameter 2 to be string, array given + -- Iteration 15 -- -- Iteration 16 -- @@ -170,4 +170,4 @@ object -- Iteration 25 -- -- Iteration 26 -- -Resource id #%d +vfprintf() expects parameter 2 to be string, resource given diff --git a/ext/standard/tests/strings/vprintf_variation1.phpt b/ext/standard/tests/strings/vprintf_variation1.phpt index 146a4e44f2..0fb8ed8a03 100644 --- a/ext/standard/tests/strings/vprintf_variation1.phpt +++ b/ext/standard/tests/strings/vprintf_variation1.phpt @@ -88,12 +88,16 @@ $values = array( $counter = 1; foreach($values as $value) { echo "\n -- Iteration $counter --\n"; - $result = vprintf($value,$args); - echo "\n"; - var_dump($result); - $counter++; + try { + $result = vprintf($value, $args); + echo "\n"; + var_dump($result); + } catch (TypeError $exception) { + echo $exception->getMessage() . "\n"; + } -}; + $counter++; +} // closing the resource fclose($file_handle); @@ -139,34 +143,19 @@ int(13) int(3) -- Iteration 10 -- - -Warning: Array to string conversion in %s on line %d -Array -int(5) +vprintf() expects parameter 1 to be string, array given -- Iteration 11 -- - -Warning: Array to string conversion in %s on line %d -Array -int(5) +vprintf() expects parameter 1 to be string, array given -- Iteration 12 -- - -Warning: Array to string conversion in %s on line %d -Array -int(5) +vprintf() expects parameter 1 to be string, array given -- Iteration 13 -- - -Warning: Array to string conversion in %s on line %d -Array -int(5) +vprintf() expects parameter 1 to be string, array given -- Iteration 14 -- - -Warning: Array to string conversion in %s on line %d -Array -int(5) +vprintf() expects parameter 1 to be string, array given -- Iteration 15 -- @@ -213,5 +202,4 @@ int(0) int(0) -- Iteration 26 -- -Resource id #%d -int(%d) +vprintf() expects parameter 1 to be string, resource given diff --git a/ext/standard/tests/strings/vsprintf_variation1.phpt b/ext/standard/tests/strings/vsprintf_variation1.phpt index 33bc043927..4b2da4b551 100644 --- a/ext/standard/tests/strings/vsprintf_variation1.phpt +++ b/ext/standard/tests/strings/vsprintf_variation1.phpt @@ -88,10 +88,13 @@ $values = array( $counter = 1; foreach($values as $value) { echo "\n -- Iteration $counter --\n"; - var_dump( vsprintf($value,$args) ); + try { + var_dump(vsprintf($value, $args)); + } catch (TypeError $exception) { + echo $exception->getMessage() . "\n"; + } $counter++; - -}; +} // closing the resource fclose($file_handle); @@ -129,29 +132,19 @@ string(13) "1.07654321E-9" string(3) "0.5" -- Iteration 10 -- - -Warning: Array to string conversion in %s on line %d -string(5) "Array" +vsprintf() expects parameter 1 to be string, array given -- Iteration 11 -- - -Warning: Array to string conversion in %s on line %d -string(5) "Array" +vsprintf() expects parameter 1 to be string, array given -- Iteration 12 -- - -Warning: Array to string conversion in %s on line %d -string(5) "Array" +vsprintf() expects parameter 1 to be string, array given -- Iteration 13 -- - -Warning: Array to string conversion in %s on line %d -string(5) "Array" +vsprintf() expects parameter 1 to be string, array given -- Iteration 14 -- - -Warning: Array to string conversion in %s on line %d -string(5) "Array" +vsprintf() expects parameter 1 to be string, array given -- Iteration 15 -- string(0) "" @@ -187,5 +180,5 @@ string(0) "" string(0) "" -- Iteration 26 -- -string(%d) "Resource id #%d" +vsprintf() expects parameter 1 to be string, resource given Done diff --git a/tests/classes/tostring_004.phpt b/tests/classes/tostring_004.phpt index 997f2e2e7f..3627cbf215 100644 --- a/tests/classes/tostring_004.phpt +++ b/tests/classes/tostring_004.phpt @@ -53,7 +53,7 @@ try { --EXPECT-- Object with no __toString(): Try 1: -Object of class stdClass could not be converted to string +printf() expects parameter 1 to be string, object given Try 2: