Menu
Borrow
finalclass
final class Borrow
Parameter attribute: the caller keeps ownership of the pointer and the callee must not free it.
The ownership attributes (Borrow, BorrowMut, Take, Give, StaticPtr)
document who owns a pointer across an FFI call. They are checked at compile
time, not lowered: nothing is freed on your behalf. They require a
{@see Symbol} on the same declaration, apply only to pointer-carrying
parameters or returns, and Give and StaticPtr exclude each other. At most
one of Borrow, BorrowMut and Take may sit on a parameter.
Take on a string and Give on a string return are rejected, because a
PHP string is reference counted and must never reach C's free().
#[Library('c'), Symbol('strlen')]
function strlen(#[Borrow] string $s): int { return 0; }See also: Symbol
Methods
__construct() | Create the attribute. |
__construct()#source
function __construct(public ?string $lifetime = null)
Create the attribute.
Parameters
$lifetimestring|null = null- optional lifetime label for documentation; it is not checked