]> granicus.if.org Git - php/commitdiff
Only accept string as the format parameter of *printf() functions
authorMáté Kocsis <kocsismate@woohoolabs.com>
Fri, 15 Nov 2019 19:31:19 +0000 (20:31 +0100)
committerMáté Kocsis <kocsismate@woohoolabs.com>
Mon, 9 Dec 2019 18:43:34 +0000 (19:43 +0100)
24 files changed:
ext/standard/formatted_print.c
ext/standard/tests/file/fscanf_variation10.phpt
ext/standard/tests/file/fscanf_variation11.phpt
ext/standard/tests/file/fscanf_variation16.phpt
ext/standard/tests/file/fscanf_variation17.phpt
ext/standard/tests/file/fscanf_variation22.phpt
ext/standard/tests/file/fscanf_variation23.phpt
ext/standard/tests/file/fscanf_variation29.phpt
ext/standard/tests/file/fscanf_variation30.phpt
ext/standard/tests/file/fscanf_variation35.phpt
ext/standard/tests/file/fscanf_variation36.phpt
ext/standard/tests/file/fscanf_variation4.phpt
ext/standard/tests/file/fscanf_variation41.phpt
ext/standard/tests/file/fscanf_variation42.phpt
ext/standard/tests/file/fscanf_variation47.phpt
ext/standard/tests/file/fscanf_variation48.phpt
ext/standard/tests/file/fscanf_variation5.phpt
ext/standard/tests/strings/printf_variation1.phpt
ext/standard/tests/strings/sprintf_variation1.phpt
ext/standard/tests/strings/vfprintf_error3.phpt
ext/standard/tests/strings/vfprintf_variation20.phpt
ext/standard/tests/strings/vprintf_variation1.phpt
ext/standard/tests/strings/vsprintf_variation1.phpt
tests/classes/tostring_004.phpt

index a5acaeea9bd7e0ba6bf0feead7b3eb26458e7ffe..c8d912793a11c7178490068c3af0f468d5b55b4d 100644 (file)
@@ -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;
index 158c6579d906dbf07e29f699822b2c9b522b2955..2b98ec31d36174a32a7ffcdccab029ac880a1f17 100644 (file)
@@ -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
index 97dfa810a293e2877e43e167010af552e7d77398..208eda05ba0ff28a1db113435867646d291b5bb2 100644 (file)
@@ -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
index a9fd0cf84d1f46161da461c1d1ad2cee604d8e78..fd71de7b25103f2441da54a3a660269968b95f1c 100644 (file)
@@ -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
index 4e976c7cb4ff1c56902715b3b15c82309fb3db06..276246535b634967a3cad853ef2ad6f55ed62f48 100644 (file)
@@ -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
index adb848a9085441e878d936fdde257412f0147d15..f65578e32d06d03679a2905da36c3f15f301d3f9 100644 (file)
@@ -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
index c1b9ca6580e9f532b28ada3186b4966800e9d7b9..b90dfde6ffdc439a104ead227c9f56baee0b2e2a 100644 (file)
@@ -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
index 1db49732906b63cb9289daa2e0620218ea0dec06..ec518a096494cac4ff1f781f914f3295ffa8db91 100644 (file)
@@ -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
index c01f5aa2e6b0e6e5f5c5da5558066b4c81f95aa4..8db09ba5db4718a2333989b34f7bd77375b4231e 100644 (file)
@@ -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
index 445280c2fd53035808261ca41e94c627cde77b67..5211e8bc9cbf782f850a88fc593e6bdc1bfe4574 100644 (file)
@@ -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
index 9eb617077dfc97978ed0b780f8e106a4d75b9579..230bf387a95dee2b479561225a002be6a7bdaa49 100644 (file)
@@ -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
index b802a90da3295d396af9f8835b06c1aefd2d324f..57906f4fc34b9970aaaeecc1b143b50396547694 100644 (file)
@@ -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
index 487954097f68c87a40f749b0dd751559b6c44883..e9bfb5ac9141b5821e12d25460b07cf3d7b108cc 100644 (file)
@@ -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
index 45cf3696b59e61556cead43bd5ace5c53e96744f..a33b5ea80696d167fd09df9d1deb4afc3b7919a9 100644 (file)
@@ -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
index 6217b32b61a4301463225adcead03ce58c951727..ecc0543bf6196d2d9b34f3bbede32d05e2c66e48 100644 (file)
@@ -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
index 355d5cf187722e4f6276d48b33801069ee168325..9b7c874a491b489f81c3e471e51fedaff207390c 100644 (file)
@@ -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
index 714a54b912a004eb52bde3b9d5a5600c7d243542..a9b92b2f86240f365e2cf54ee504b1422da04d81 100644 (file)
@@ -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
index 0884a2ff71798dae24168120ed5844a30b27012f..4ec032f9ce6187ffb210d710197a2040b5745ee9 100644 (file)
@@ -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
index 33320b9f1c8f24b2e95a365e0f2af99fce61968f..f30cf5182ec3e51bcb126e137925d531554d314d 100644 (file)
@@ -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
index 06103878a63ebdd80c74546347f2e6333864dca1..0496d9b19cb14185796aa6838696a0eb59be2c31 100644 (file)
@@ -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"
index c831674bcd0fb403e8bd3cfaaf2d5232b82406a9..17426c7af75ce23f601ba02332f7b678c4694fbb 100644 (file)
@@ -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
index 146a4e44f2127f8b75d1ec23cebb71b7a87d0b72..0fb8ed8a03d051e49a1d9d6d57865af2099a3992 100644 (file)
@@ -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
index 33bc043927b94ca0ba9630300178ca61693f507d..4b2da4b55105f5613c3bb92d5184ec9bcb0e8fc4 100644 (file)
@@ -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
index 997f2e2e7fdb4309559c12693b83c2bbdc3d8966..3627cbf215790482a78350365c87f46869da9b19 100644 (file)
@@ -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: