Skip to content

Commit ccec410

Browse files
committed
Add object and resource tests to array_(sum|product)()
1 parent b505562 commit ccec410

File tree

5 files changed

+45
-7
lines changed

5 files changed

+45
-7
lines changed

ext/standard/tests/array/array_product_variation1.phpt

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,20 @@ echo "*** Testing array_product() : variation - using non numeric values ***\n";
77
class A {
88
static function help() { echo "hello\n"; }
99
}
10-
$fp = fopen(__FILE__, "r");
1110

1211
$types = array("boolean (true)" => true, "boolean (false)" => false,
1312
"string" => "hello", "numeric string" => "12",
14-
"resource" => $fp, "object" => new A(), "null" => null,
13+
"resource" => STDERR, "object" => new A(), "null" => null,
1514
"array" => array(3,2));
1615

1716
foreach ($types as $desc => $type) {
18-
echo $desc . "\n";
19-
var_dump(array_product(array($type)));
17+
echo $desc, "\n";
18+
var_dump(array_product([1, $type]));
2019
echo "\n";
2120
}
2221

23-
fclose($fp);
2422
?>
25-
--EXPECTF--
23+
--EXPECT--
2624
*** Testing array_product() : variation - using non numeric values ***
2725
boolean (true)
2826
int(1)
@@ -37,7 +35,7 @@ numeric string
3735
int(12)
3836

3937
resource
40-
int(%d)
38+
int(3)
4139

4240
object
4341
int(1)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
--TEST--
2+
Test array_product() function: ressources in array
3+
--FILE--
4+
<?php
5+
$input = [10, STDERR /* Should get casted to 3 as an integer */];
6+
var_dump(array_product($input));
7+
?>
8+
--EXPECT--
9+
int(30)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--TEST--
2+
Test array_product() function with objects castable to numeric type
3+
--EXTENSIONS--
4+
gmp
5+
--FILE--
6+
<?php
7+
$input = [gmp_init(25), gmp_init(6)];
8+
var_dump(array_product($input));
9+
?>
10+
--EXPECT--
11+
int(1)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
--TEST--
2+
Test array_sum() function: ressources in array
3+
--FILE--
4+
<?php
5+
$input = [10, STDERR /* Should get casted to 3 as an integer */];
6+
var_dump(array_sum($input));
7+
?>
8+
--EXPECT--
9+
int(13)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--TEST--
2+
Test array_sum() function with objects castable to numeric type
3+
--EXTENSIONS--
4+
gmp
5+
--FILE--
6+
<?php
7+
$input = [gmp_init(25), gmp_init(6)];
8+
var_dump(array_sum($input));
9+
?>
10+
--EXPECT--
11+
int(0)

0 commit comments

Comments
 (0)