Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

get_resource_type
resource_type
php
communitycreator

What is the get_resource_type() method in PHP?

Programming Bytes

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

The get_resource_type method can be used to get the type of a resource.

In PHP, resource denotes a reference to an external resource. For example, a resource variable can point to a file or database connection.


The list of available resource types can be found here.


Syntax


get_resource_type(resource $resource): string

Parameter and return value

This method will generate an error and return null if the passed argument is not a resource.

Code

<?php
$res = tmpfile();
echo "The resource type of the temporary file is : ";
echo get_resource_type($res) . "\n";
?>

Explanation

In the code above:

  • We use the tmpfile() method to create a temporary file.

  • We use the get_resource_type method to get the resource type of the file. We will get stream as the result.

RELATED TAGS

get_resource_type
resource_type
php
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring