|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2004-09-10 18:21 UTC] jon at latchkey dot com
Description:
------------
[6][ /private/tmp ]% cat test2.php
<?
function doA()
{
return true;
}
function doB()
{
return true;
}
?>
<? if (doA()) { ?>here1<? } else ?>
<? if (doB()) { ?>here2<? } ?>
<? if (doA()) { ?>here3<? ?>
<? } else if (doB()) { ?>here4<? } ?>
[7][ /private/tmp ]% php --version
PHP 5.0.0 (cli) (built: Aug 3 2004 15:10:22)
Copyright (c) 1997-2004 The PHP Group
Zend Engine v2.0.0, Copyright (c) 1998-2004 Zend Technologies
[8][ /private/tmp ]% php test2.php
here1here2
here3
[9][ /private/tmp ]%
Reproduce code:
---------------
<?
function doA()
{
return true;
}
function doB()
{
return true;
}
?>
<? if (doA()) { ?>here1<? } else ?>
<? if (doB()) { ?>here2<? } ?>
<? if (doA()) { ?>here3<? ?>
<? } else if (doB()) { ?>here4<? } ?>
Expected result:
----------------
here1here2
here3here4
(or a compile error)
Actual result:
--------------
here1here2
here3
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Dec 02 13:00:01 2025 UTC |
This is not a support forum. Please ask support questions on the appropriate mailing list. But your logic boils down to: if(true) echo "here1"; else <empty expression>; if(true) echo "here2"; if(true) echo "here3"; else if(true) echo "here4"; In the first part you don't have anything in your else clause as you never started a block using {...} so the expression ends with the end of the PHP block. In the second part the else expression only gets evaluated if the if condition was false. It doesn't matter that the condition after the else happens to be true, it won't be evaluated.