CKTIS / PHP
PHP-type never
Alleen als retourtype toegestaan.
Versie: PHP 8.4; repository runtime, production runtime not attested
Syntax
function stop(): neverAlleen als retourtype toegestaan. De functie keert nooit normaal terug: ze kan een uitzondering werpen, het proces beëindigen of eindeloos doorlopen. De aanroeper kan de uitzondering buiten de functie opvangen. Zowel return als normaal het einde bereiken schendt het contract.
function stop(): never { throw new RuntimeException('closed'); }
try { stop(); } catch (RuntimeException $e) { echo $e->getMessage(); }
closed
Voorbeelden
<?php
function stop(): never { throw new RuntimeException('closed'); }
try { stop(); } catch (RuntimeException $e) { echo $e->getMessage(); }
Resultaat
closed