PHP/resource: Difference between revisions

from HTYP, the free directory anyone can edit if they can prove to me that they're not a spambot
< PHP
No edit summary
No edit summary
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
{{fmt/title|the "resource" data-type in PHP}}
==About==
==About==
In [[PHP]], a "resource" value is an opaque internal pointer for handling certain types of I/O-ish operations.
In [[PHP]], a "resource" value is an opaque internal pointer for handling certain types of I/O-ish operations.
Line 7: Line 8:
{| class=wikitable
{| class=wikitable
! type || subtype || functions
! type || subtype || functions
{{!-!}} curl || cURL handle
{{!-!}} [[/curl/]] || cURL handle
{{!-!}} process || || <code>[https://www.php.net/manual/en/function.proc-open.php proc_open()], [https://www.php.net/manual/en/function.proc-get-status.php proc_get_status()], [https://www.php.net/manual/en/function.proc-terminate.php proc_terminate()], [https://www.php.net/manual/en/function.proc-close.php proc_close()]</code>
{{!-!}} [[/process/]] || || <code>[https://www.php.net/manual/en/function.proc-open.php proc_open()], [https://www.php.net/manual/en/function.proc-get-status.php proc_get_status()], [https://www.php.net/manual/en/function.proc-terminate.php proc_terminate()], [https://www.php.net/manual/en/function.proc-close.php proc_close()]</code>
{{!-!}} stream || dir handle
{{!-!}} [[/stream/]] || dir handle
{{!-!}} stream || file handle
{{!-!}} [[/stream/]] || file handle
{{!-!}} stream || process handle
{{!-!}} [[/stream/]] || process handle
{{!-!}} socket || file handle
{{!-!}} [[/socket/]] || file handle
{{!-!}} ssh2 session
{{!-!}} [[/ssh2/]] session
{{!-!}} ssh2 listener
{{!-!}} [[/ssh2/]] listener
{{!-!}} ssh2 SFTP
{{!-!}} [[/ssh2/]] SFTP
{{!-!}} ssh2 publickey system
{{!-!}} [[/ssh2/]] publickey system
|}
|}
Source: [https://www.php.net/manual/en/resource.php List of Resource Types]
Source: [https://www.php.net/manual/en/resource.php List of Resource Types]

Latest revision as of 17:31, 10 February 2026

the "resource" data-type in PHP

{{#set: page title=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).

Reference