get_resource_type

(PHP 4 >= 4.0.2, PHP 5, PHP 7, PHP 8)

get_resource_type 返回资源类型

说明

get_resource_type(resource $resource): string

此函数获取指定资源的类型。

参数

resource

要求值的资源句柄。

返回值

如果指定 resource 是资源,则此函数将返回表示其类型的字符串。如果此函数未识别类型,则返回值是字符串 Unknown

如果 resource 不是 resource,则此函数将返回 null 并生成错误。

范例

示例 #1 get_resource_type() 示例

<?php
$fp
= fopen("foo", "w");
echo
get_resource_type($fp) . "\n";

// 从 PHP 8.0.0 开始,以下内容不再起作用。curl_init 函数现在返回 CurlHandle 对象。
$c = curl_init();
echo
get_resource_type($c) . "\n";
?>

以上例程在 PHP 7 中的输出:

stream
curl

参见

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top