From:             ian at avionwbt dot co dot uk
Operating system: Win 2003 Web Edition IIS6
PHP version:      5.2.1
PHP Bug Type:     CGI related
Bug description:  User defined function return incorrect characters

Description:
------------
The comma-separated return string from a user-defined function sometimes
(about 20%, erratically) returns a pipe ('|') separated return string
instead of a comma-separated string.

The function works through a two-dimensional array, applying scaling
factors to some elements and returning the modified first-dimension array. 
The example code below has been abbreviated by removing conditional
(if-else) blocks for simplification.

This problem has been traced by writing the return out to a log file,
clips of which are listed below.

This code worked fine in PHP 4, but became erratice after upgrade to
PHP5.

Note also that following upgrade to PHP 5 that the code failed fatally
until the "if(!function_exists('calcPrice')){" condition was added.

Reproduce code:
---------------
if(!function_exists('calcPrice')){
        function calcPrice($prod){
                global $vat;                                    
                global $cFactor;
                global $lessonData;

                $curr = $lessonData[$prod]['currentPrice'];
                $name = $lessonData[$prod]['name'];

                $v = ($curr*$lessonData[$prod]['netVATrate'])*0.01;
                $p0 = $cFactor * ($curr+$v);
                return (  "$prod,$p0,$curr,$name,0");   
                }
        }
}
foreach($lsnArray as $value){   # $lsnArray is external
$p = calcPrice($value);

# For reasons which escape me entirely, the 
# function calcPrice() periodically returns 
# a string with '|' separators instead of  ','  !!!!!! 

$item = str_replace( "|", ",",$p);    # work-around solution

$pricelist .= "&$value=$item";        # Required URL-encoded output
                 
fwrite($LOG, "\r\nPricelist element: $value=$p");   # TRACE


Expected result:
----------------
Log file clip, achieved about 80% of instances (erratic):

Pricelist increment: INTR=INTR,0,0.00,Introduction to Tutor,0
Pricelist increment: OV01=OV01,11.75,10.00,Overview of the PRINCE2
Pricelist increment: OV02=OV02,15.275,13.00,Principles of PRINCE2,0
Pricelist increment: BC01=BC01,12.925,11.00,Business Case,0
Pricelist increment: OR01=OR01,16.45,14.00,Project Organisation,0
Pricelist increment: PR01=PR01,29.9625,25.50,Overview of PRINCE2
Processes,0
...
etc


Actual result:
--------------
Log file clip, actual about 20% of instances (erratic):

Pricelist increment: INTR=INTR|0|0|Introduction to Tutor|0
Pricelist increment: OV01=OV01|11.75|10|Overview of the PRINCE2 Method|0
Pricelist increment: OV02=OV02|15.275|13|Principles of PRINCE2|0
Pricelist increment: BC01=BC01|12.925|11|Business Case|0
Pricelist increment: OR01=OR01|16.45|14|Project Organisation|0
Pricelist increment: PR01=PR01|29.962|25.5|Overview of PRINCE2
Processes|0
...
etc


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

Reply via email to