Created
November 3, 2023 20:39
-
-
Save richardDobron/e1d004744746c379e639a483c51e57b3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* A utility that accepts a value and throws an Exception if the value is null, | |
* otherwise it returns the value. | |
* | |
* @throws Exception | |
*/ | |
function nullthrows(mixed $value, string $message = null): mixed | |
{ | |
if ($value !== null) { | |
return $value; | |
} | |
throw new Exception($message ?: 'Got unexpected null value.'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment