|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-04-24 11:45 UTC] ian at avionwbt dot co dot uk
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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Wed Jul 22 17:00:01 2026 UTC |
This bug report is withdrawn by the originator. Reason: Not a bug. Explanation: 1. Amongst many scripts, two subroutine functions with the same name existed, with slightly different output - one with comma separators, and one with '|' separators. These functions used different input data, but the same operations. 2. The upgrade of PHP from 4 to 5 required the wrapping of user-defined functions with if(!function_exists('name'){... else a fatal error was thrown (can't redefine functions). 3. In PHP 4 the subroutine functions were redefined on each invocation. In PHP 5 the current function depended on application sequencing, giving rise to different output formats. 4. Oops.