summaryrefslogtreecommitdiff
path: root/ext/standard/tests/array/count_invalid.phpt
blob: b4fb27c8a967bf02781accd8fdf47fc0c1d144b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
--TEST--
Only arrays and countable objects can be counted
--FILE--
<?php

try {
    $result = count(null);
    var_dump($result);
} catch (\TypeError $e) {
    echo $e->getMessage() . \PHP_EOL;
}

try {
    $result = count("string");
    var_dump($result);
} catch (\TypeError $e) {
    echo $e->getMessage() . \PHP_EOL;
}

try {
    $result = count(123);
    var_dump($result);
} catch (\TypeError $e) {
    echo $e->getMessage() . \PHP_EOL;
}

try {
    $result = count(true);
    var_dump($result);
} catch (\TypeError $e) {
    echo $e->getMessage() . \PHP_EOL;
}

try {
    $result = count(false);
    var_dump($result);
} catch (\TypeError $e) {
    echo $e->getMessage() . \PHP_EOL;
}

try {
    $result = count((object) []);
    var_dump($result);
} catch (\TypeError $e) {
    echo $e->getMessage() . \PHP_EOL;
}

?>
--EXPECT--
count(): Argument #1 ($var) must be of type Countable|array, null given
count(): Argument #1 ($var) must be of type Countable|array, string given
count(): Argument #1 ($var) must be of type Countable|array, int given
count(): Argument #1 ($var) must be of type Countable|array, bool given
count(): Argument #1 ($var) must be of type Countable|array, bool given
count(): Argument #1 ($var) must be of type Countable|array, stdClass given