From:             arpad at rajeczy dot com
Operating system: linux 2.6.13 x86_64
PHP version:      5CVS-2005-10-29 (CVS)
PHP Bug Type:     Arrays related
Bug description:  array_product() is broken

Description:
------------
The array_product() function is completely broken, it  
returns 0 for all valid input and when the input is an  
empty array. 
  
Having looked at ext/standard/array.c, array_product()  
seems to be a straight copy of array_sum(), but with '+'  
replaced by  '*'. As in array_sum(), the initial  
return_value is 0, but because the elements are multiplied  
with return_value rather than added to it, the result is  
always 0.  

Reproduce code:
---------------
<pre><?php

$tests = array(
        'foo',
        array(),
        array(0),
        array(3),
        array(3, 3),
        array(0.5, 2),
        array(99999999, 99999999)
);

foreach ($tests as $v) {
        echo 'testing: (', (is_array($v) ? implode(' * ', $v) : $v),
")\n\tresult: ";
        var_dump(array_product($v));
        echo "\n\n"; 
}

?></pre>

Expected result:
----------------
testing: (foo) 
        result:  
 
Warning:  array_product() [function.array-product]: The 
argument should be an array 
in /usr/local/apache2/htdocs/a/t.php on line 14 
 
NULL 
 
 
testing: () 
        result:  
 
Warning:  array_product() [function.array-product]: Array 
must contain at least one element 
in /usr/local/apache2/htdocs/a/t.php on line 14 
 
NULL 
 
 
testing: (0) 
        result: int(0) 
 
 
testing: (3) 
        result: int(3) 
 
 
testing: (3 * 3) 
        result: int(9) 
 
 
testing: (0.5 * 2) 
        result: float(1) 
 
 
testing: (9999999 * 9999999) 
        result: int(99999980000001) 

Actual result:
--------------
testing: (foo) 
        result:  
 
Warning:  array_product() [function.array-product]: The 
argument should be an array 
in /usr/local/apache2/htdocs/a/t.php on line 14 
 
NULL 
 
 
testing: () 
        result: int(0) 
 
 
testing: (0) 
        result: int(0) 
 
 
testing: (3) 
        result: int(0) 
 
 
testing: (3 * 3) 
        result: int(0) 
 
 
testing: (0.5 * 2) 
        result: float(0) 
 
 
testing: (99999999 * 99999999) 
        result: int(0) 

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

Reply via email to