Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

PHP type false

The literal type false describes exactly the boolean value false, for example a disabled flag.

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

Syntax

function lookup(string $key): int|false

The literal type false describes exactly the boolean value false, for example a disabled flag. It lets a return union distinguish a missing item from a valid integer zero. A strict comparison preserves that distinction. Since PHP 8.2 false may also be declared as a standalone type. A false-like string or integer is not the literal false value.

declare(strict_types=1);
function lookup(string $key): int|false { return $key === 'first' ? 0 : false; }
echo json_encode([lookup('first'), lookup('first') === false, lookup('missing') === false]);
[0,false,true]

Examples

<?php
declare(strict_types=1);
function lookup(string $key): int|false { return $key === 'first' ? 0 : false; }
echo json_encode([lookup('first'), lookup('first') === false, lookup('missing') === false]);

Result

[0,false,true]

Sources