php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30054 not getting the expected output i think i should get
Submitted: 2004-09-10 18:21 UTC Modified: 2004-09-11 20:37 UTC
From: jon at latchkey dot com Assigned:
Status: Not a bug Package: Output Control
PHP Version: 5.0.0 OS: OSX
Private report: No CVE-ID: None
 [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 


Patches

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-09-11 15:18 UTC] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php


 [2004-09-11 19:31 UTC] jon at latchkey dot com
tell me why this is a bug.
 [2004-09-11 19:32 UTC] jon at latchkey dot com
tell me why this is not a bug. sorry.
 [2004-09-11 20:37 UTC] rasmus@php.net
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Aug 17 16:01:29 2024 UTC