#40669 [NEW]: problem with ternary operateor

Ask a Question related to PHP Bugs, Design and Development.

  1. #1

    Default #40669 [NEW]: problem with ternary operateor

    From: milman at gmx dot de
    Operating system:
    PHP version: 5.2.1
    PHP Bug Type: Scripting Engine problem
    Bug description: problem with ternary operateor

    Description:
    ------------
    $a = 1 + (1) ? 2 : 5 ;

    should be the same as

    $a = 1 + ((1) ? 2 : 5);

    as

    $a = 3 ;

    Reproduce code:
    ---------------
    <?php
    echo "<body><xmp>\n" ;

    $a = 1 + (1) ? 2 : 5 ;
    echo "wrong: $a\n" ;

    $a = 1 + ((1) ? 2 : 5);
    echo "right: $a\n" ;

    echo "</xmp></body>\n" ;
    ?>

    Expected result:
    ----------------
    wrong: 3
    right: 3



    Actual result:
    --------------
    wrong: 2
    right: 3



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

  2. Similar Questions and Discussions

    1. #25841 [Opn->Bgs]: ternary returns by-value rather than by-reference, although if/else works fine
      ID: 25841 Updated by: sniper@php.net Reported By: pluggz24 at yahoo dot com -Status: Open +Status: ...
    2. #25841 [NEW]: ternary returns by-value rather than by-reference, although if/else works fine
      From: pluggz24 at yahoo dot com Operating system: Slackware Linux 8.1, Windows XP PHP version: 4.3.2 PHP Bug Type: ...
    3. Problem playing Quicktime thru .DCR embedded in HTML - pathreferencing problem?
      Greetings earthlings and Director heads. Here's the problem: created an HTML file containing shockwave (dcr) movie that calls quicktime movies in...
    4. #21611 [Opn]: Problem with version_compare() (Was: Problem with pear cli and release numbers)
      ID: 21611 Updated by: et@php.net -Summary: Problem with pear cli and release numbers Reported By: jan at horde...
    5. Problem with Apache Web Server config file and PHP (please give advice on what problem may be me)
      HI: Can anyone refer me to someone that can help with the problem below. I installed Apache Web Server on my laptop which has Windows XP. I...
  3. #2

    Default #40669 [Opn->Bgs]: problem with ternary operateor

    ID: 40669
    Updated by: [email]tony2001@php.net[/email]
    Reported By: milman at gmx dot de
    -Status: Open
    +Status: Bogus
    Bug Type: Scripting Engine problem
    PHP Version: 5.2.1
    New Comment:

    Thank you for taking the time to write to us, but this is not
    a bug. Please double-check the documentation available at
    [url]http://www.php.net/manual/[/url] and the instructions on how to report
    a bug at [url]http://bugs.php.net/how-to-report.php[/url]

    [url]http://www.php.net/manual/en/language.operators.php[/url]


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

    [2007-02-28 18:36:03] milman at gmx dot de

    Description:
    ------------
    $a = 1 + (1) ? 2 : 5 ;

    should be the same as

    $a = 1 + ((1) ? 2 : 5);

    as

    $a = 3 ;

    Reproduce code:
    ---------------
    <?php
    echo "<body><xmp>\n" ;

    $a = 1 + (1) ? 2 : 5 ;
    echo "wrong: $a\n" ;

    $a = 1 + ((1) ? 2 : 5);
    echo "right: $a\n" ;

    echo "</xmp></body>\n" ;
    ?>

    Expected result:
    ----------------
    wrong: 3
    right: 3



    Actual result:
    --------------
    wrong: 2
    right: 3




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


    --
    Edit this bug report at [url]http://bugs.php.net/?id=40669&edit=1[/url]
    tony2001@php.net Guest

  4. #3

    Default #40669 [Bgs]: problem with ternary operateor

    ID: 40669
    User updated by: milman at gmx dot de
    Reported By: milman at gmx dot de
    Status: Bogus
    Bug Type: Scripting Engine problem
    PHP Version: 5.2.1
    New Comment:

    sorry, but i dosn't understand.

    why must i write

    $a = 1 + ((1) ? 2 : 5);

    and

    $a = 1 + (1) ? 2 : 5 ;
    get a wrong result.

    that is totaly unexpected.

    i think it is to easy to say in documentation you should use
    () with ternary operator.

    than it should get a syntax-error when using without in expressions.
    but not a wrong result.


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

    [2007-02-28 18:49:56] [email]tony2001@php.net[/email]

    Thank you for taking the time to write to us, but this is not
    a bug. Please double-check the documentation available at
    [url]http://www.php.net/manual/[/url] and the instructions on how to report
    a bug at [url]http://bugs.php.net/how-to-report.php[/url]

    [url]http://www.php.net/manual/en/language.operators.php[/url]

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

    [2007-02-28 18:36:03] milman at gmx dot de

    Description:
    ------------
    $a = 1 + (1) ? 2 : 5 ;

    should be the same as

    $a = 1 + ((1) ? 2 : 5);

    as

    $a = 3 ;

    Reproduce code:
    ---------------
    <?php
    echo "<body><xmp>\n" ;

    $a = 1 + (1) ? 2 : 5 ;
    echo "wrong: $a\n" ;

    $a = 1 + ((1) ? 2 : 5);
    echo "right: $a\n" ;

    echo "</xmp></body>\n" ;
    ?>

    Expected result:
    ----------------
    wrong: 3
    right: 3



    Actual result:
    --------------
    wrong: 2
    right: 3




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


    --
    Edit this bug report at [url]http://bugs.php.net/?id=40669&edit=1[/url]
    milman at gmx dot de Guest

Posting Permissions

  • You may not post new threads
  • You may 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