Created
May 21, 2018 08:40
-
-
Save HavenShen/8f4d05689c6133199063e4607391646b to your computer and use it in GitHub Desktop.
PHP 7 增加了对返回类型声明的支持。 类似于参数类型声明,返回类型声明指明了函数返回值的类型。可用的类型与参数声明中可用的类型相同。
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 | |
/* | |
|-------------------------------------------------------------------------- | |
| 返回类型声明 | |
|-------------------------------------------------------------------------- | |
| | |
| PHP 7 增加了对返回类型声明的支持。 类似于参数类型声明,返回类型声明指明了函数返回值的类型。可用的类型与参数声明中可用的类型相同。 | |
| | |
*/ | |
function reverseString($string) : string | |
{ | |
return $string; | |
} | |
echo reverseString('Haven Shen'); | |
// Demo | |
interface StorageInterface | |
{ | |
public function get($key) : string; | |
} | |
class SessionStorage implements StorageInterface | |
{ | |
public function get($key) : string | |
{ | |
return 'string'; | |
} | |
} | |
$sessionStoreage = new SessionStorage; | |
echo $sessionStoreage->get('test'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment