• PHP Video Tutorials

PHP - get_resource_type() Function


Advertisements

Definition and Usage

The get_resource_type() function returns the type of a resource.

Syntax

string get_resource_type ( resource $handle )

Parameters

Sr.No Parameter & Description
1

handle

The evaluated resource handle.

Return Values

  • 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.

Dependencies

PHP 4.0.2 and above.

Example

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";
?>

Output

This will produce following result (it returns a string representing its type) −

stream

Example

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";
?>

Output

This will produce following result (it returns the string Unknown) −

Unknown

Example

Following example demonstrates the use of function get_resource_type() when handle is null −

<?php
   $resource = null;
   echo get_resource_type($resource) . "\n";
?>

Output

This will produce an error in logs as below −

PHP Warning:   get_resource_type() expects parameter 1 to be resource, null given
php_variable_handling_functions.htm

Useful Video Courses


Video

PHP Online Training

45 Lectures 9 hours

Malhar Lathkar

Video

Become PHP Facebook Developer: Password-Less Authentication

34 Lectures 4 hours

Syed Raza

Video

Ultimate PHP & MySQL Web Development Course & OOP Coding

84 Lectures 5.5 hours

Frahaan Hussain

Video

Learn PHP from Scratch

17 Lectures 1 hours

Nivedita Jain

Video

E Commerce Website Development In PHP With PDO

100 Lectures 34 hours

Azaz Patel

Video

PHP in Telugu

43 Lectures 5.5 hours

Vijay Kumar Parvatha Reddy

Advertisements