Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有没有更清洁的方法来做到这一点?
/** * Will return either a 1 or 0 * * @return int|boolean */ public function getExitCode() { return $this->exitCode; }
它不会将值转换为布尔值,而是将其转换为整数。
如果它返回一个int你的文档应该说它返回一个 int。但是,您可以描述它:
int
/** * @return int 0 on success, non-zero indicates failure */
这也允许未来的扩展。如果您的退出代码被更改以提供比“是”或“否”更有用的信息怎么办?“不,因为 XYZ” 可以用 以外的数字表示1,并且您的文档仍然是正确的(这意味着函数的实现不需要更改,除非他们想利用新信息)
1