What is a Resource Type in PHP? What is it for?


I'm new to the PHP language, studying about it, I came across a special type available by the language, the resource type. I found a definition for it:


A resource is a special variable, which holds a reference to an external resource. Resources are created and used by special functions.

Source: https://secure.php.net/manual/pt_BR/language.types.resource.php

What is a resource type? What is it for? What is its applicability in practice?


resource is a php type, it is used for various purposes like making database connections, opening/manipulating files or working with streams.

As the manual says basically resorce is something returned through a specific function (can be fopen , mysqli_connect etc) that communicates with something external in other words it is a handler.

List of resources in PHP

Scroll to Top