If-Condition:为什么要将布尔值转换为整数


If-Condition: Why turning a boolean into an integer?

我看到这样一个条件:

if ((int)method_exists($this, $this->endpoint) > 0)

这背后是什么?比起显而易见的

,它的优势是什么?
if (method_exists($this, $this->endpoint))

?

(来源:http://coreymaynard.com/blog/creating-a-restful-api-with-php/)

我看不出把它变成整数有什么好处。因为method_exists已经返回了一个布尔值。这是一种冗长而无用的编码方式。

if语句需要一个布尔值,而method_exists返回一个布尔值,在那里添加的进程与直接使用method_exists得到的结果完全相同(但是浪费时间和cpu,所以请不要这样做:D)