php中成员函数名后的冒号(:)运算符是什么意思

use*_*474 5 php oop

我想知道方法名称后冒号的含义即

公共函数 getTitle():Data {

interface Data { 
     public function details(string $name);
}
class Company {
     private $title;

     public function getTitle():Data {
      return $this->title;
     }

     public function setTitle(Data $title)
     {
      $this->title=$title
     }

}

.....
.....
Run Code Online (Sandbox Code Playgroud)

T. *_*OUT 5

public function getTitle():Data {
     return $this->title;
}
Run Code Online (Sandbox Code Playgroud)

返回类型声明”自 PHP 7.0 起添加(此方法应返回类型为“Data”的对象)。

与“参数类型声明”一样,“返回类型声明”是可选的。

检查 PHP 7.0 中引入的新功能

检查此链接 http://php.net/manual/en/migration70.new-features.php

  • 作为附加信息,如果返回的值[无法转换为指定类型](http://sandbox.onlinephpfunctions.com/code/e8a04f88f485659358759cca4ff322238ade493a),或者如果[严格输入]( http://php.net/manual/en/functions.arguments.php#functions.arguments.type-declaration.strict) 被激活。 (3认同)