Created
May 24, 2020 16:20
-
-
Save alfianmalik/2d2af593bc4dabd622765e7d942d2ace to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
declare(strict_types=1); | |
/** | |
* @param bool $error | |
* @param null $message | |
* @return string | |
*/ | |
function printError(bool $error, $message = null): ?string | |
{ | |
if ($error) { | |
$message = 'You have encountered an error'; | |
// Initial null variable now contains a string value | |
// even with strict type enforcement | |
} | |
return $message; | |
} | |
$message = printError(true, null); | |
echo $message; // 'You have encountered an error' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment