rstoll;11021905 wrote:Well, if
$a = "a";
then
$a == (int) $a
evaluates to true because the == does make a weak comparision and thus $a would be castet to a int before it is compared against (int) $a and consequentely $a and (int) $a are the same.
yeah... it'd have to be implemented some other way.
rstoll;11021905 wrote:Maybe it would be nice if a developer can decide on his own if he wants an auto casting or not.
I'd thought about that. I was considering using
function foo( (int)$a ){ /* cast $a if necessary */ }
function bar( int $a ){ /* no casting; strict equality only */ }
seems more intuitive to me.
To answer bradgrafelman and NogDog,
I agree that casting "if equivalent" wouldn't actually work very well, and that, if you ask for a particular type you should expect the comparison to be strict. The only examples where I'm hesitant (that I can think of) is 1/0 vs. TRUE/FALSE and numeric strings vs. integers.