Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

PHP type never

A never return type promises that no normal return occurs.

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

Syntax

function stop(): never

A never return type promises that no normal return occurs. The function may throw, terminate execution or keep running. A caller can handle a thrown exception and continue outside the function. Returning a value, returning without a value or falling through the end violates this contract. The type is available only for returns.

function stop(): never { throw new RuntimeException('closed'); }
try { stop(); } catch (RuntimeException $e) { echo $e->getMessage(); }
closed

Examples

<?php
function stop(): never { throw new RuntimeException('closed'); }
try { stop(); } catch (RuntimeException $e) { echo $e->getMessage(); }

Result

closed

Sources