hwechselberg
hwechselberg

Reputation: 105

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

I saw a condition like this:

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

What's behind this? What's the advantage over the obvious

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

?

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

Upvotes: 4

Views: 94

Answers (1)

Fabrice Kabongo
Fabrice Kabongo

Reputation: 668

I don't see any advantage of turning it into an integer. because method_exists already return a boolean. It is a long and useless way of coding.

if statement require a boolean, and method_exists return a boolean, the process added there has the exact same result than using directly method_exists (but waste time and cpu, so please don't do that :D)

Upvotes: 5

Related Questions