← All built-ins / malloc()

malloc()

unsafe
malloc(int $n): mixed

Parameters

NameTypeDescription
$nintbyte count

Return value

Raw pointer to n bytes (unsafe block required). Free with free().

Example

echo "// unsafe { $p = malloc(1024); memset($p, 0, 1024); free($p); }";
// unsafe { $p = malloc(1024); memset($p, 0, 1024); free($p); }

This call needs a real environment (window, server, database or stdin) — the snippet above shows the typical usage shape.

See also

free()memset()memcpy()ffi_load()