PHP Function Reference

PHP get_resource_type() Function



The PHP get_resource_type() function returns the type of the specified resource.

Syntax

get_resource_type(resource)

Parameters

resource Required. Specify the evaluated resource handle.

Return Value

Returns a string representing the type of the given resource. If the type is not identified by this function, the return value will be the string Unknown.

The function returns null and generate an error if resource is not a resource.

Example:

Lets assume that we have a file called test.txt in the current working directory. The example below demonstrates on using this function to get the type of the specified resource.

<?php
$file = 'test.txt';

$fp = fopen($file, 'r');

//getting the type of this resource
echo "Resource type: ".get_resource_type($fp);
?>

The output of the above code will be:

Resource type: stream

❮ PHP Variable Handling Reference