5

I want to know the meaning of colon after method name i.e.

public function 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
     }

}

.....
.....
user3653474
  • 2,035
  • 1
  • 24
  • 57

1 Answers1

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

"Return type declaration" added since PHP 7.0 (This method should return an object having type "Data").

Like "Argument type declaration", "Return type declaration" is optional.

to check the new features introduced in PHP 7.0

check this link http://php.net/manual/en/migration70.new-features.php

T. AKROUT
  • 1,629
  • 6
  • 18
  • 3
    As aditional information, PHP will throw a `TypeError`, if the value that is returned [cannot be converted to the specified type](http://sandbox.onlinephpfunctions.com/code/e8a04f88f485659358759cca4ff322238ade493a), or if [strict typing](http://php.net/manual/en/functions.arguments.php#functions.arguments.type-declaration.strict) is activated. – Philipp Maurer Apr 10 '18 at 07:47