Edit report at http://bugs.php.net/bug.php?id=51283&edit=1

 ID:               51283
 Updated by:       johan...@php.net
 Reported by:      easteregg at verfriemelt dot org
 Summary:          defect stringconcatination with if term
-Status:           Open
+Status:           Bogus
 Type:             Bug
 Package:          *General Issues
 Operating System: windows 2008 & linux
 PHP Version:      5.3.2

 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
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Please see php.net7operators for the Operator Precedence.What happensis
that in



  $order .= ' ' . ($this->data["order"] == 1) ? "desc" : "asc";



The expression



  ' ' . ($this->data["order"] == 1)



will be evaluated first. Depending on the result "desc" or"asc" will be
evaluated and returned.



Use parenthesis:



  $order .= ' ' . (($this->data["order"] == 1) ? "desc" : "asc");


Previous Comments:
------------------------------------------------------------------------
[2010-03-12 13:26:12] easteregg at verfriemelt dot org

Description:
------------
if i concat some strings like $string .= ' ' . (true)? asd : foo ;

the whitespace is always missing..

see code snipped!

Test script:
---------------
<?php

class test {

    public $data = array();

    public function __construct() {

      

      $this->data["sort"] = "erstellt";

      $this->data["order"] = "1";

      

      $order = null;

      if (isset($this->data["sort"])) {

          $order = $this->data["sort"];

          if (isset($this->data["order"])) $order .= ' ' .
($this->data["order"] == 1) ? "desc" : "asc";

      }

      echo $order;

      //returns erstelltdesc



      echo "\n------------------------------\n";

      

      $order = null;

      if (isset($this->data["sort"])) {

          $order = $this->data["sort"];

          if (isset($this->data["order"]))  {

              $order .= ' ';

              $order .= ($this->data["order"] == 1) ? "desc" : "asc";

          }

      }

      echo $order;

      //returns erstellt desc

    }

}

new test()

?> 

Expected result:
----------------
erstellt desc

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

erstellt desc

Actual result:
--------------
erstelltdesc

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

erstellt desc


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



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=51283&edit=1

Reply via email to