ID:               41176
 User updated by:  ian at avionwbt dot co dot uk
 Reported By:      ian at avionwbt dot co dot uk
-Status:           Feedback
+Status:           Open
 Bug Type:         CGI related
 Operating System: Win 2003 Web Edition IIS6
 PHP Version:      5.2.1
 New Comment:

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.


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

[2007-04-24 11:49:56] [EMAIL PROTECTED]

Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.



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

[2007-04-24 11:45:24] 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



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


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

Reply via email to