PHP get_resource_type() Function
The get_resource_type() function is an inbuilt function in PHP that is used for returning the type of resource.
Syntax:
get_resource_type(resource $resource)
Parameters: This function accepts one parameter that described below:
- $resource: This parameter specifies the evaluated resource handle name.
Return Values: The function will return the string representing its type if the given resource is a resource. If the function does not determine the type of resource It will return Unknown.
Example 1: In the following example, we will print the type of resource by using the get_resource_type() function.
<?php
$file_text = fopen("text.txt","rb") ;
echo get_resource_type($file_text) ;
?>
Output:
stream
Example 2: In the below example, will print the Unknown when you used the get_resource_type() function without passing any resource to the function.
<?php
$file_text = fopen("text.txt","rb") ;
echo get_resource_type($file_text)."\n" ;
fclose($file_text);
echo get_resource_type($file_text) ;
?>
Output:
stream Unknown
Reference: https://www.php.net/manual/en/function.get-resource-type.php