#212924 - 2017-11-21 07:57 PM
IIF()
|
ShaneEP
MM club member
Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
|
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...
$array = '1','2','3'
$test = IIf(1, $array[0], $array[3]) This fails because array[3] is out of bounds, even though in my opinion it should only evaluate the code that says array[0] and ignore the other block.
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?
|
Top
|
|
|
|
#212929 - 2017-11-21 09:58 PM
Re: IIF()
[Re: Jochen]
|
ShaneEP
MM club member
Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
|
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.
$array = '0','1','2','3','4','5'
$x = 50
$test = IIf($x<6, $array[$x], $array[$x mod 10])
Edited by ShaneEP (2017-11-21 09:59 PM)
|
Top
|
|
|
|
#212932 - 2017-11-22 05:04 PM
Re: IIF()
[Re: Jochen]
|
ShaneEP
MM club member
Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
|
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...
$array = '0','1','2','3','4','5'
$x = 51
If $x < 6
$test = $array[$x]
Else
$test = $array[$x mod 10]
Endif Then the IIF equivalent should as well, in my opinion.
$array = '0','1','2','3','4','5'
$x = 51
$test = IIf($x < 6, $array[$x], $array[$x mod 10])
|
Top
|
|
|
|
#212933 - 2017-11-22 05:17 PM
Re: IIF()
[Re: ShaneEP]
|
Allen
KiX Supporter
Registered: 2003-04-19
Posts: 4549
Loc: USA
|
|
Top
|
|
|
|
Moderator: ShaneEP, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Ruud van Velsen, Mart
|
0 registered
and 370 anonymous users online.
|
|
|