I boiled my problem down to this template code on a template with "Allow PHP" set to "YES" and "PHP Parsing Stage" set to "Output":
{if 1 == 1}
First block
<?php echo '1 == 1 is true'; ?>
<?php $test = 'hello'; ?>
{if:else}
Second block
<?php echo '1 == 1 is false'; ?>
<?php $test = 'goodbye'; ?>
{/if}
<?php echo $test; ?>
The output is:
First block
1 == 1 is true
goodbye
But I would expect the output to be:
First block
1 == 1 is true
hello
I don't understand how the 1 == 1 is true
line could get echoed while the variable $test
gets set to "goodbye". It seems like my PHP variable assignments statements all get executed whether or not the conditional block they are in should get executed or not.
Update
This is apparently still a problem even when I eliminate the PHP from the template:
{if 1 == 1}
1 == 1 is true
{exp:stash:set name="test"}hello{/exp:stash:set}
{if:else}
1 == 1 is false
{exp:stash:set name="test"}goodbye{/exp:stash:set}
{/if}
{exp:stash:test}
The output is:
1 == 1 is true
goodbye