The get_resource_type() function returns the type of a resource.
string get_resource_type ( resource $handle )
Sr.No | Parameter & Description |
---|---|
1 |
handle The evaluated resource handle. |
If the given handle is a resource, this function will return a string representing its type.
If the type is not identified by this function, the return value will be the string Unknown.
This function will return null and generate an error if handle is not a resource.
PHP 4.0.2 and above.
Following example demonstrates the use of function get_resource_type() with valid resource −
<?php $resource = fopen("test.txt", "w"); echo get_resource_type($resource) . "\n"; ?>
This will produce following result (it returns a string representing its type) −
stream
Following example demonstrates the use of function get_resource_type() with released resource −
<?php $resource = fopen("test.txt", "w"); fclose($resource); echo get_resource_type($resource) . "\n"; ?>
This will produce following result (it returns the string Unknown) −
Unknown
Following example demonstrates the use of function get_resource_type() when handle is null −
<?php $resource = null; echo get_resource_type($resource) . "\n"; ?>
This will produce an error in logs as below −
PHP Warning: get_resource_type() expects parameter 1 to be resource, null given