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
}
}
.....
.....
It indicates the type of value that the function returns, and it's not limited to arrays. For example, you can use float , int or even your own class: class MyClass { } function something(): MyClass { return new MyClass(); }
The Scope Resolution Operator (also called Paamayim Nekudotayim) or in simpler terms, the double colon, is a token that allows access to static, constant, and overridden properties or methods of a class.
This (:) operator mostly used in embedded coding of php and html. Using this operator you can avoid use of curly brace.
There are two distinct ways to access methods in PHP, but what's the difference? sfConfig::set('foo', 'bar'); I'm assuming -> (dash with greater than sign or chevron) is used for functions for variables, and :: (double colons) is used for functions for classes.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With