php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30238 string concatenation with . terminates while using ternary ? operator
Submitted: 2004-09-26 03:13 UTC Modified: 2004-09-27 10:07 UTC
From: kossarev at hytti dot uku dot fi Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 4.3.9RC3 OS: Windows 2000
Private report: No CVE-ID: None
 [2004-09-26 03:13 UTC] kossarev at hytti dot uku dot fi
Description:
------------
Firstly, thank you for developing the great and powerful PHP language.

And the bug: consider the following code.. (from next box)

the first . operation terminates prematurely while using the ternary operator at the end of the statement. 
so i have to use a version commented out by /* */

Reproduce code:
---------------
for ($i=2; $i<=$loop_count; $i++)
{ //bug is in the first statement:
  $query_string .= $dest_fields[$i-1][0]." = '".$init_array[$i]."'".($i<$loop_count)?(", "):(" ");*/
//so i have to use this version:
  /*$query_string .= $dest_fields[$i-1][0]." = '".$init_array[$i]."'";
  $query_string .= ($i<$loop_count)?(", "):(" ");*/
}


Expected result:
----------------
i expect concatenation operation to use values in $dest_fields and $init_array[, which contain simple string values (database columns and respective fields):
user_id = '225', last_edit = '2004-09-26 04:08:40', language_id = '1', title = 'dfdfdsfdsa', province_id = '1', locality = 'Monako', selftype_id = '1', searchedtype_id = '1', purpose_id = '2', submenu_id = '0', messagetext = 'adsf ?fds?lkfdas?kfd?k j?a'


Actual result:
--------------
using a 1-line statement version, i only get the result of ternary comparison in the resulting $query_string:
, , , , , , , , , , ,
somehow values in $dest_table and $init_array[$] get skipped..

i suspect that presence of a ? ternary operator causes
the string concatenation with . to exit prematurely. it however works when devided into two lines of code (commented out in the code example) 



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-09-27 10:07 UTC] derick@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions. 

Thank you for your interest in PHP.

No bug, this is related to operator precedence.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Wed Feb 11 10:00:02 2026 UTC