Last active
July 14, 2018 22:19
-
-
Save yoander/7678930d742956789d3fc5cb1ce123e7 to your computer and use it in GitHub Desktop.
PHP 7.1 New Features
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 | |
function returnStringOrNull($valueToReturn): ?string { | |
return $valueToReturn; | |
} | |
echo 'LibreByte:', gettype(returnStringOrNull('LibreByte')), nl2br("\n"); | |
echo 'null:', gettype(returnStringOrNull(null)), nl2br("\n"); | |
echo '25:', gettype(returnStringOrNull(25)), nl2br("\n"); | |
echo 'SdtClass object:', gettype(returnStringOrNull(new StdClass())), nl2br("\n"); |
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 | |
function stringOrNullParam(?string $param) { | |
echo 'Param: ', is_null($param) ? "'null'" : "'$param'", ", type: ", gettype($param), nl2br("\n"); | |
} | |
stringOrNullParam('LibreByte'); | |
stringOrNullParam(null); | |
stringOrNullParam(25); | |
stringOrNullParam(new StdClass()); |
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 | |
a = 10; | |
function voidWithoutReturn(&$param, $newValue): void { | |
$param = $newValue; | |
} | |
function voidWithEmptyReturn(&$param, $newValue): void { | |
$param = $newValue; | |
return; | |
} | |
echo 'Initial value for a: ', $a, nl2br("\n"); | |
voidWithoutReturn($a, 25); | |
echo 'Called voidWithoutReturn($a, 25), $a = ', $a, nl2br("\n"); | |
voidWithEmptyReturn($a, 30); | |
echo 'Called voidWithEmptyReturn($a, 30), a = ', $a, nl2br("\n"); |
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 | |
function voidWithReturn(): void { | |
return 1; | |
} |
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 | |
function voidWithReturnNull(): void { | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment