<?php
function sayHello(string $name): never
{
echo "Hello, $name";
exit(); // if we comment this line, php throws fatal error
}
sayHello("John"); // result: "Hello, John"
never es únicamente un tipo de retorno que indica que la función no se termina. Esto significa que llama a exit(), lanza una excepción, o es un bucle infinito. Por lo tanto, no puede formar parte de una declaración de type union Disponible a partir de PHP 8.1.0.
never es, en el lenguaje de la teoría de tipos, el tipo vacío. Esto significa que es el subtipo de todos los otros tipos y que puede reemplazar cualquier otro tipo de retorno durante la herencia.
<?php
function sayHello(string $name): never
{
echo "Hello, $name";
exit(); // if we comment this line, php throws fatal error
}
sayHello("John"); // result: "Hello, John"
I think the description should be corrected from return-only to non-return function since the context is now misleading