php8.5
Home/ Manual/ ffi / ffi/ FFI::cast

FFI::cast

PHP function Edit on GitHub ✎

(PHP 7 >= 7.4.0, PHP 8)

Performs a C type cast

Description

FFI::cast(FFI\CType|string $type, FFI\CData|int|float|bool|null $ptr): FFI\CData|null

FFI::cast creates a new FFI\CData object, that references the same C data structure, but is associated with a different type. The resulting object does not own the C data, and the source ptr must survive the result. The C type may be specified as a string with any valid C type declaration or as FFI\CType object, created before. Any type declared for the instance is allowed.

Parameters

type

A valid C declaration as string, or an instance of FFI\CType which has already been created.

ptr

The handle of the pointer to a C data structure.

Return Values

Returns the freshly created FFI\CData object.

Changelog

VersionDescription
8.3.0Calling FFI::cast statically is now deprecated.

Source: reference/ffi/ffi/cast.xml · from the official PHP manual (php/doc-en)