Menu

Reference / Ffi

Ptr

finalclass
final class Ptr

An opaque C pointer: a raw address with no automatic free.

Use it for C handles that PHP holds but never dereferences (a FILE*, a library cookie), as a parameter or return type of an FFI binding. The caller owns the lifetime of whatever the address refers to, and the runtime does not check it: using a dangling or out-of-bounds address is undefined behaviour.

See also: Symbol, Library

Methods

__construct()Wrap a raw address.
null()The null pointer (address 0).
isNull()Whether the address is 0.
offset()A new pointer $bytes bytes past this one (negative moves back).

__construct()#source

function __construct(public int $address)

Wrap a raw address.

Parameters

$address int
the address; 0 is the null pointer

null()#source

static function null(): self

The null pointer (address 0).

Returns

self — a pointer for which {@see isNull} is true

isNull()#source

function isNull(): bool

Whether the address is 0.

Returns

bool — true for the null pointer

offset()#source

function offset(int $bytes): self

A new pointer $bytes bytes past this one (negative moves back). No bounds are checked.

Parameters

$bytes int
byte displacement

Returns

self — the displaced pointer

View source