【问题标题】:What is the meaning of colon (:) operator after member function name in php [duplicate]php中成员函数名后的冒号(:)运算符是什么意思[重复]
【发布时间】:2018-04-10 07:37:02
【问题描述】:

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

公共函数getTitle():数据{

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
     }

}

.....
.....

【问题讨论】:

    标签: php oop


    【解决方案1】:
    public function getTitle():Data {
         return $this->title;
    }
    

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

    和“Argument type declaration”一样,“返回类型声明”是可选的。

    查看 PHP 7.0 中引入的新功能

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

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-05-05
    • 2016-08-12
    • 1970-01-01
    • 1970-01-01
    • 2012-09-25
    • 2011-04-01
    • 2011-06-17
    • 2011-03-31
    相关资源
    最近更新 更多