Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

PHP type void

A void return declaration describes a procedure called for its effects.

Version: PHP 8.4; repository runtime, production runtime not attested

Syntax

function record(array &$log, string $text): void

A void return declaration describes a procedure called for its effects. It can finish normally or use an empty return to leave early. It cannot return a value, including an explicit null. The result of the call nevertheless evaluates to null. A never function, in contrast, cannot finish by returning normally.

function record(array &$log, string $text): void { if ($text === '') { return; } $log[] = $text; }
$log = [];
record($log,'');
$result = record($log,'ok');
echo json_encode([$log,$result]);
[["ok"],null]

Examples

<?php
function record(array &$log, string $text): void { if ($text === '') { return; } $log[] = $text; }
$log = [];
record($log,'');
$result = record($log,'ok');
echo json_encode([$log,$result]);

Result

[["ok"],null]

Sources