|
|
|||||||
This may or may not be considered a bug. But it seems weird to me though, so figured I would bring it to light to see what others think. It appears that IIF() evaluates data in all blocks, instead of just the block that should be returned. Example... Code: $array = '1','2','3' $test = IIf(1, $array[0], $array[3]) I ran across this issue, trying to golf down some code, so it probably wouldn't be an issue for most uses. But what do you guys think? |
||||||||
|
|
|||||||
Interesting, I‘d rather have it failing my code for sanity‘s sake than stabbing me in the back on runtime though |
||||||||
|
|
|||||||
But there are legitimate uses for such logic...Let me expound on the example a bit.. If $x is 5 or less it works, but will cause error when above 5, even though the second block would function. Code: $array = '0','1','2','3','4','5' $x = 50 $test = IIf($x<6, $array[$x], $array[$x mod 10]) |
||||||||
|
|
|||||||
Still, checking sanity of array boundaries is one thing I wouldn't want to have ommited. As $x is 'variable' in most use cases and not 'constant' Let's hear the others out though |
||||||||
|
|
|||||||
I agree with what you're saying. But in my mind, IIF() should act exactly like an If, Else, Endif. And in currently doesn't. If this code works without error... Code: $array = '0','1','2','3','4','5' $x = 51 If $x < 6 $test = $array[$x] Else $test = $array[$x mod 10] Endif Code: $array = '0','1','2','3','4','5' $x = 51 $test = IIf($x < 6, $array[$x], $array[$x mod 10]) |
||||||||
|
|
|||||||
I was thinking this has/had come up before... see if this helps. http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=79397#Post79397 |
||||||||
|
|
|||||||
Yeah, I guess that makes sense. Since it passes to a function, it always gets evaluated. So not really a bug. At least I wasn't the only one to think it was weird! lol |
||||||||
|
|
|||||||
Yep, what |