summaryrefslogtreecommitdiff
path: root/ext/standard/tests/array/array_filter_variation9.phpt
blob: f5158e337ccc95986e6cbc00ff02ab491fe482f3 (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
57
58
59
60
61
62
63
64
65
66
67
68
69
--TEST--
Test array_filter() function : usage variations - built-in functions as 'callback' argument
--FILE--
<?php
/*
* Passing built-in functions and different language constructs as 'callback' argument
*/

echo "*** Testing array_filter() : usage variations - built-in functions as 'callback' argument ***\n";

$input = array(0, 1, -1, 10, 100, 1000, null);

// using built-in function 'is_int' as 'callback'
var_dump( array_filter($input, 'is_int') );

// using built-in function 'chr' as 'callback'
var_dump( array_filter($input, 'chr') );

// using language construct 'echo' as 'callback'
try {
    var_dump( array_filter($input, 'echo') );
} catch (TypeError $e) {
    echo $e->getMessage(), "\n";
}

// using language construct 'exit' as 'callback'
try {
    var_dump( array_filter($input, 'exit') );
} catch (TypeError $e) {
    echo $e->getMessage(), "\n";
}

echo "Done"
?>
--EXPECT--
*** Testing array_filter() : usage variations - built-in functions as 'callback' argument ***
array(6) {
  [0]=>
  int(0)
  [1]=>
  int(1)
  [2]=>
  int(-1)
  [3]=>
  int(10)
  [4]=>
  int(100)
  [5]=>
  int(1000)
}
array(7) {
  [0]=>
  int(0)
  [1]=>
  int(1)
  [2]=>
  int(-1)
  [3]=>
  int(10)
  [4]=>
  int(100)
  [5]=>
  int(1000)
  [6]=>
  NULL
}
array_filter(): Argument #2 ($callback) must be a valid callback, function "echo" not found or invalid function name
array_filter(): Argument #2 ($callback) must be a valid callback, function "exit" not found or invalid function name
Done