PHP: Hypertext Preprocessor (original) (raw)
Never
never is a return-only type indicating the function does not terminate. This means that it either calls exit(), throws an exception, or is an infinite loop. Therefore, it cannot be part of aunion type declaration. Available as of PHP 8.1.0.
never is, in type theory parlance, the bottom type. Meaning it is the subtype of every other type and can replace any other return type during inheritance.
Found A Problem?
2 years ago
<?phpfunction sayHello(string $name): never { echo "Hello, $name"; exit(); // if we comment this line, php throws fatal error }sayHello("John"); // result: "Hello, John"
6 months ago
I think the description should be corrected from return-only to non-return function since the context is now misleading