1
0
mirror of https://github.com/php/php-src.git synced 2026-04-03 06:02:23 +02:00
Files
archived-php-src/ext/standard/tests/strings/vfprintf_error3.phpt
2020-05-25 17:29:46 +02:00

60 lines
1.3 KiB
PHP

--TEST--
Test vfprintf() function : error conditions (wrong argument types)
--CREDITS--
Felix De Vliegher <felix.devliegher@gmail.com>
--INI--
precision=14
--FILE--
<?php
/* Prototype : int vfprintf(resource stream, string format, array args)
* Description: Output a formatted string into a stream
* Source code: ext/standard/formatted_print.c
* Alias to functions:
*/
// Open handle
$file = 'vfprintf_error3.txt';
$fp = fopen( $file, "a+" );
echo "\n-- Testing vfprintf() function with wrong variable types as argument --\n";
try {
vfprintf($fp, array( 'foo %d', 'bar %s' ), 3.55552);
} catch (TypeError $exception) {
echo $exception->getMessage() . "\n";
}
try {
vfprintf($fp, "Foo: %s", "not available");
} catch (TypeError $e) {
echo $e->getMessage(), "\n";
}
try {
vfprintf($fp, "Foo %y fake", ["not available"]);
} catch (ValueError $e) {
echo $e->getMessage(), "\n";
}
rewind( $fp );
var_dump( stream_get_contents( $fp ) );
ftruncate( $fp, 0 );
rewind( $fp );
// Close handle
fclose( $fp );
?>
--CLEAN--
<?php
$file = 'vfprintf_error3.txt';
unlink( $file );
?>
--EXPECT--
-- Testing vfprintf() function with wrong variable types as argument --
vfprintf(): Argument #2 ($format) must be of type string, array given
vfprintf(): Argument #3 ($args) must be of type array, string given
Unknown format specifier 'y'
string(0) ""