break;
default:
- php_error_docref(NULL, E_WARNING, "Can only process string or stream arguments");
- RETURN_FALSE;
+ zend_argument_type_error(2, "must be of type resource|string, %s given", zend_zval_type_name(what));
+ RETURN_THROWS();
}
magic = magic_open(MAGIC_MIME_TYPE);
php_stream_wrapper *wrap;
php_stream_statbuf ssb;
- if (buffer == NULL || !*buffer) {
- php_error_docref(NULL, E_WARNING, "Empty filename or path");
- RETVAL_FALSE;
+ if (buffer == NULL || buffer_len == 0) {
+ zend_argument_value_error(1, "cannot be empty");
goto clean;
}
if (CHECK_NULL_PATH(buffer, buffer_len)) {
- php_error_docref(NULL, E_WARNING, "Invalid path");
- RETVAL_FALSE;
+ zend_argument_type_error(1, "must not contain null bytes");
goto clean;
}
}
break;
}
-
- default:
- php_error_docref(NULL, E_WARNING, "Can only process string or stream arguments");
+ EMPTY_SWITCH_DEFAULT_CASE()
}
common:
<?php
$fp = finfo_open();
-var_dump(finfo_file($fp, "\0"));
-var_dump(finfo_file($fp, ''));
-var_dump(finfo_file($fp, NULL));
+try {
+ var_dump(finfo_file($fp, "\0"));
+} catch (\TypeError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+try {
+ var_dump(finfo_file($fp, ''));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+try {
+ var_dump(finfo_file($fp, NULL));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
var_dump(finfo_file($fp, '.'));
var_dump(finfo_file($fp, '&'));
?>
--EXPECTF--
-Warning: finfo_file(): Empty filename or path in %s on line %d
-bool(false)
-
-Warning: finfo_file(): Empty filename or path in %s on line %d
-bool(false)
-
-Warning: finfo_file(): Empty filename or path in %s on line %d
-bool(false)
+finfo_file(): Argument #1 ($finfo) must not contain null bytes
+finfo_file(): Argument #1 ($finfo) cannot be empty
+finfo_file(): Argument #1 ($finfo) cannot be empty
string(9) "directory"
Warning: finfo_file(&): Failed to open stream: No such file or directory in %s on line %d
var_dump( finfo_file( $finfo, __FILE__) );
var_dump( finfo_file( $finfo, __FILE__, FILEINFO_CONTINUE ) );
var_dump( finfo_file( $finfo, $magicFile ) );
-var_dump( finfo_file( $finfo, $magicFile.chr(0).$magicFile) );
+
+try {
+ var_dump( finfo_file( $finfo, $magicFile.chr(0).$magicFile) );
+} catch (\TypeError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
?>
---EXPECTF--
+--EXPECT--
*** Testing finfo_file() : basic functionality ***
string(28) "text/x-php; charset=us-ascii"
-string(%d) "PHP script, ASCII text%A"
+string(22) "PHP script, ASCII text"
string(32) "text/plain; charset=unknown-8bit"
-
-Warning: finfo_file(): Invalid path in %s%efinfo_file_basic.php on line %d
-bool(false)
+finfo_file(): Argument #1 ($finfo) must not contain null bytes
--FILE--
<?php
-mime_content_type(1);
-mime_content_type(NULL);
-mime_content_type(new stdclass);
-mime_content_type(array());
+try {
+ mime_content_type(1);
+} catch (\TypeError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+try {
+ mime_content_type(NULL);
+} catch (\TypeError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+try {
+ mime_content_type(new stdclass);
+} catch (\TypeError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+try {
+ mime_content_type(array());
+} catch (\TypeError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+
mime_content_type('foo/inexistent');
-mime_content_type('');
-mime_content_type("\0");
+
+try {
+ mime_content_type('');
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+try {
+ mime_content_type("\0");
+} catch (\TypeError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
?>
--EXPECTF--
-Warning: mime_content_type(): Can only process string or stream arguments in %s on line %d
-
-Warning: mime_content_type(): Can only process string or stream arguments in %s on line %d
-
-Warning: mime_content_type(): Can only process string or stream arguments in %s on line %d
-
-Warning: mime_content_type(): Can only process string or stream arguments in %s on line %d
+mime_content_type(): Argument #2 must be of type resource|string, int given
+mime_content_type(): Argument #2 must be of type resource|string, null given
+mime_content_type(): Argument #2 must be of type resource|string, stdClass given
+mime_content_type(): Argument #2 must be of type resource|string, array given
Warning: mime_content_type(foo/inexistent): Failed to open stream: No such file or directory in %s on line %d
-
-Warning: mime_content_type(): Empty filename or path in %s on line %d
-
-Warning: mime_content_type(): Empty filename or path in %s on line %d
+mime_content_type(): Argument #1 ($filename) cannot be empty
+mime_content_type(): Argument #1 ($filename) must not contain null bytes