Base de conhecimentoCentro de Exames
PT · PTPortuguês (Portugal)
Escolher idioma13

CKTIS / PHP

Tipo do PHP false

O tipo literal false descreve apenas o valor booleano false.

Versão: PHP 8.4; repository runtime, production runtime not attested

Sintaxe

function lookup(string $key): int|false

O tipo literal false descreve apenas o valor booleano false. Em união com int, distingue a chave válida 0 do indicador de falha false. Verifique a falha com === false. Desde PHP 8.2, false também pode ser declarado isoladamente.

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]

Exemplos

<?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]);

Resultado

[0,false,true]

Fontes