[英]PHP mixed in getters and setters
Im using Php with doctrine and have a question regarding its setters/getters 我将Php与教义结合使用时,对设置者/获取者有疑问
Accordning to php.net mixed is "mixed indicates that a parameter may accept multiple (but not necessarily all) types..." but why shall i use it when my $id is an int and will always be ? 据php.net混合是“混合表明一个参数可以接受多个(但不一定是所有)类型...”,但是当我的$ id是一个int且将永远是它时,为什么要使用它呢? When should i use the "mixed" in getters and setters such as this ?
我什么时候应该在这样的吸气剂和塞脂剂中使用“混合”?
/**
* @param mixed $id
* @return $this
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
/**
* @return mixed
*/
public function getId()
{
return $this->id;
}
You should used a mix argument and/or return type when the value type may different. 当值类型可能不同时,应使用混合参数和/或返回类型。 For example if the same function may return an array for one call and an int for another.
例如,如果同一个函数可能为一个调用返回一个数组,而为另一个调用返回一个int。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.