Scripting Error with Nested 'If'
Posted: 11 Nov 2011 13:13
The result of the following code is wrong!
It's a simplified excerpt from real code, just to test/show the problem.
(Note: $b *could* be '', too.)
The first If correctly recognizes 'True' and executes it's conditional code: OK.
The second If correctly recognizes 'False', but nevertheless executes it's conditional code: that's wrong!
"Stepping" shows for the condition of the 2nd If
b = ''
but then the conditional
$a = 'cc'
is wrongly executed!
In the moment when stepping shows
$a = 'cc';
you can look for Variables: $a still contains 'b'! Then it's overwritten.
It's a simplified excerpt from real code, just to test/show the problem.
(Note: $b *could* be '', too.)
Code: Select all
$a = '';
$b = 'b';
if ($a = '')
{ $a = $b;
if ($a = '') {$a = 'cc';}
}
Msg $a; The second If correctly recognizes 'False', but nevertheless executes it's conditional code: that's wrong!
"Stepping" shows for the condition of the 2nd If
b = ''
but then the conditional
$a = 'cc'
is wrongly executed!
In the moment when stepping shows
$a = 'cc';
you can look for Variables: $a still contains 'b'! Then it's overwritten.