PHP/resource

from HTYP, the free directory anyone can edit if they can prove to me that they're not a spambot
< PHP
Jump to navigation Jump to search
the "resource" data-type in PHP

About

In PHP, a "resource" value is an opaque internal pointer for handling certain types of I/O-ish operations.

Syntax

As of PHP 8.5, although "resource" is "soft-reserved and is used as a documentation pseudotype, there is no actual "resource" type; the only type which is currently known to be compatible with resource variables is "mixed". PHP currently interprets invocation of "resource" as a type as a reference to an unknown class named "<current namespace>\resource".

Types

There are many specialty resource-types defined by extensions, and a handful of more general types:

type subtype functions
curl cURL handle
process proc_open(), proc_get_status(), proc_terminate(), proc_close()
stream dir handle
stream file handle
stream process handle
socket file handle
ssh2 session
ssh2 listener
ssh2 SFTP
ssh2 publickey system

Source: List of Resource Types

Advanced

New stream resource types can be defined in code with stream_wrapper_register().

Functions

These are just the general functions that apply to all resources; there are many others that do things with specific types of resources. In general, this is all not very well documented (there is plenty of documentation, but very little of it explains how things work).

Links

Reference