Professional Web Applications Themes

#40218 [NEW]: Add Else clause to while - PHP Bugs

From: jbailey at raspberryginger dot com Operating system: Linux PHP version: 5.2.0 PHP Bug Type: Feature/Change Request Bug description: Add Else clause to while Description: ------------ Right now checks have to be done separately for when a while will execute zero times, which means code duplication and constructs that have to be kept in sync. I would like to see an else clause to while that is executed when the while loop goes zero times. Reproduce code: --------------- while (0) { echo "I ran"; } else { echo "I didn't run."; } Expected result: ---------------- I didn't run. Actual result: ...

  1. #1

    Default #40218 [NEW]: Add Else clause to while

    From: jbailey at raspberryginger dot com
    Operating system: Linux
    PHP version: 5.2.0
    PHP Bug Type: Feature/Change Request
    Bug description: Add Else clause to while

    Description:
    ------------
    Right now checks have to be done separately for when a while will execute
    zero times, which means code duplication and constructs that have to be
    kept in sync. I would like to see an else clause to while that is
    executed when the while loop goes zero times.

    Reproduce code:
    ---------------
    while (0) {
    echo "I ran";
    } else {
    echo "I didn't run.";
    }



    Expected result:
    ----------------
    I didn't run.


    Actual result:
    --------------
    P error: syntax error, unexpected T_ELSE in /tmp/test.php on line 5


    --
    Edit bug report at [url]http://bugs.php.net/?id=40218&edit=1[/url]
    --
    Try a CVS snapshot (PHP 4.4): [url]http://bugs.php.net/fix.php?id=40218&r=trysnapshot44[/url]
    Try a CVS snapshot (PHP 5.2): [url]http://bugs.php.net/fix.php?id=40218&r=trysnapshot52[/url]
    Try a CVS snapshot (PHP 6.0): [url]http://bugs.php.net/fix.php?id=40218&r=trysnapshot60[/url]
    Fixed in CVS: [url]http://bugs.php.net/fix.php?id=40218&r=fixedcvs[/url]
    Fixed in release: [url]http://bugs.php.net/fix.php?id=40218&r=alreadyfixed[/url]
    Need backtrace: [url]http://bugs.php.net/fix.php?id=40218&r=needtrace[/url]
    Need Reproduce Script: [url]http://bugs.php.net/fix.php?id=40218&r=needscript[/url]
    Try newer version: [url]http://bugs.php.net/fix.php?id=40218&r=oldversion[/url]
    Not developer issue: [url]http://bugs.php.net/fix.php?id=40218&r=support[/url]
    Expected behavior: [url]http://bugs.php.net/fix.php?id=40218&r=notwrong[/url]
    Not enough info: [url]http://bugs.php.net/fix.php?id=40218&r=notenoughinfo[/url]
    Submitted twice: [url]http://bugs.php.net/fix.php?id=40218&r=submittedtwice[/url]
    register_globals: [url]http://bugs.php.net/fix.php?id=40218&r=globals[/url]
    PHP 3 support discontinued: [url]http://bugs.php.net/fix.php?id=40218&r=php3[/url]
    Daylight Savings: [url]http://bugs.php.net/fix.php?id=40218&r=dst[/url]
    IIS Stability: [url]http://bugs.php.net/fix.php?id=40218&r=isapi[/url]
    Install GNU Sed: [url]http://bugs.php.net/fix.php?id=40218&r=gnused[/url]
    Floating point limitations: [url]http://bugs.php.net/fix.php?id=40218&r=float[/url]
    No Zend Extensions: [url]http://bugs.php.net/fix.php?id=40218&r=nozend[/url]
    MySQL Configuration Error: [url]http://bugs.php.net/fix.php?id=40218&r=mysqlcfg[/url]
    jbailey at raspberryginger dot com Guest

  2. #2

    Default #40218 [Opn]: Add Else clause to while

    ID: 40218
    User updated by: jbailey at raspberryginger dot com
    Reported By: jbailey at raspberryginger dot com
    Status: Open
    Bug Type: Feature/Change Request
    Operating System: Linux
    PHP Version: 5.2.0
    New Comment:

    Grr.. This bug tracking system ate my comment. So here's a much
    shorter version of what I wrote:

    Use cases:

    Retrieving from a database (especially since PDO doesn't have a numrows
    options):

    while ($foo = $db->sql_fetchrow($result)) {
    // Do something
    } else {
    // No rows found
    }

    This could also be useful for ArrayObjects and foreach:

    $i = $myArray->getIterator();

    foreach ($i as $item) {
    // Do something
    } else {
    // Empty array
    }


    Previous Comments:
    ------------------------------------------------------------------------

    [2007-01-24 14:18:57] jbailey at raspberryginger dot com

    Description:
    ------------
    Right now checks have to be done separately for when a while will
    execute zero times, which means code duplication and constructs that
    have to be kept in sync. I would like to see an else clause to while
    that is executed when the while loop goes zero times.

    Reproduce code:
    ---------------
    while (0) {
    echo "I ran";
    } else {
    echo "I didn't run.";
    }



    Expected result:
    ----------------
    I didn't run.


    Actual result:
    --------------
    P error: syntax error, unexpected T_ELSE in /tmp/test.php on line
    5



    ------------------------------------------------------------------------


    --
    Edit this bug report at [url]http://bugs.php.net/?id=40218&edit=1[/url]
    jbailey at raspberryginger dot com Guest

  3. #3

    Default #40218 [Com]: Add Else clause to while

    ID: 40218
    Comment by: didou at keliglia dot com
    Reported By: jbailey at raspberryginger dot com
    Status: Open
    Bug Type: Feature/Change Request
    Operating System: Linux
    PHP Version: 5.2.0
    New Comment:

    I like the idea, but using the "else" keyword would break a lot of apps
    using something like this:

    if (X)
    while (foo) {

    }
    else
    no X

    whileelse ?


    Previous Comments:
    ------------------------------------------------------------------------

    [2007-01-24 14:31:11] jbailey at raspberryginger dot com

    Grr.. This bug tracking system ate my comment. So here's a much
    shorter version of what I wrote:

    Use cases:

    Retrieving from a database (especially since PDO doesn't have a numrows
    options):

    while ($foo = $db->sql_fetchrow($result)) {
    // Do something
    } else {
    // No rows found
    }

    This could also be useful for ArrayObjects and foreach:

    $i = $myArray->getIterator();

    foreach ($i as $item) {
    // Do something
    } else {
    // Empty array
    }

    ------------------------------------------------------------------------

    [2007-01-24 14:18:57] jbailey at raspberryginger dot com

    Description:
    ------------
    Right now checks have to be done separately for when a while will
    execute zero times, which means code duplication and constructs that
    have to be kept in sync. I would like to see an else clause to while
    that is executed when the while loop goes zero times.

    Reproduce code:
    ---------------
    while (0) {
    echo "I ran";
    } else {
    echo "I didn't run.";
    }



    Expected result:
    ----------------
    I didn't run.


    Actual result:
    --------------
    P error: syntax error, unexpected T_ELSE in /tmp/test.php on line
    5



    ------------------------------------------------------------------------


    --
    Edit this bug report at [url]http://bugs.php.net/?id=40218&edit=1[/url]
    didou at keliglia dot com Guest

Similar Threads

  1. Using IN in a WHERE clause
    By drmaves in forum Coldfusion Database Access
    Replies: 15
    Last Post: September 5th, 05:05 PM
  2. CF MX 6 WHERE Clause
    By Jeremy5431 in forum Macromedia ColdFusion
    Replies: 13
    Last Post: May 2nd, 02:26 PM
  3. Using variable in From clause
    By Glenn Stein in forum Microsoft SQL / MS SQL Server
    Replies: 4
    Last Post: July 3rd, 08:45 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139