CKTIS / PHP
Tipo de PHP false
El tipo literal false describe únicamente el valor booleano false.
Versión: PHP 8.4; repository runtime, production runtime not attested
Sintaxis
function lookup(string $key): int|falseEl tipo literal false describe únicamente el valor booleano false. En unión con int distingue la clave válida 0 de la marca de fallo false. Comprueba el fallo con === false. Desde PHP 8.2 también puede declararse false por sí solo.
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]
Ejemplos
<?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]