Skip to content

Instantly share code, notes, and snippets.

@HavenShen
Created May 21, 2018 08:43
Show Gist options
  • Save HavenShen/4d64e4960f685558669a0d728905ef38 to your computer and use it in GitHub Desktop.
Save HavenShen/4d64e4960f685558669a0d728905ef38 to your computer and use it in GitHub Desktop.
在 PHP 5 中只能是类名、接口、array 或者 callable,新增 string、int、float 和 bool。
<?php
/*
|--------------------------------------------------------------------------
| 标量类型声明
|--------------------------------------------------------------------------
|
| 在 PHP 5 中只能是类名、接口、array 或者 callable,新增 string、int、float 和 bool。
|
*/
// PHP 7 之前
class User
{
public function update($id, array $properties)
{
if (! is_int($id)) {
throw new Exception;
}
}
}
$user = new User;
$user->update('Haven Shen', []);
// PHP 7 之后
class User
{
public function update(int $id, array $properties)
{
// ...update
}
}
$user = new User;
$user->update('Haven Shen', []);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment