Skip to content

Instantly share code, notes, and snippets.

@HavenShen
Created May 21, 2018 08:40
Show Gist options
  • Save HavenShen/8f4d05689c6133199063e4607391646b to your computer and use it in GitHub Desktop.
Save HavenShen/8f4d05689c6133199063e4607391646b to your computer and use it in GitHub Desktop.
PHP 7 增加了对返回类型声明的支持。 类似于参数类型声明,返回类型声明指明了函数返回值的类型。可用的类型与参数声明中可用的类型相同。
<?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