1 | <?php |
---|
2 | /** |
---|
3 | * do_action and do_action_ref_array callback testsuite for referenced parameters. |
---|
4 | */ |
---|
5 | |
---|
6 | echo '<pre>'; |
---|
7 | printf("PHP Version: %s (allow_call_time_pass_reference: %d)\n\n", PHP_VERSION, ini_get('allow_call_time_pass_reference')); |
---|
8 | |
---|
9 | function callback_std($att) { |
---|
10 | global $called; |
---|
11 | $called++; |
---|
12 | $att = 'modified'; |
---|
13 | } |
---|
14 | |
---|
15 | function callback_ref(&$ref) { |
---|
16 | global $called; |
---|
17 | $called++; |
---|
18 | $ref = 'modified'; |
---|
19 | } |
---|
20 | |
---|
21 | $hook = 'test_hook'; |
---|
22 | |
---|
23 | $callbacks = array( |
---|
24 | 'callback_std', |
---|
25 | 'callback_ref', |
---|
26 | ); |
---|
27 | |
---|
28 | $mask = " #%02d: %s(), %-52s = \"%s\"%s\n"; |
---|
29 | $called_label = array(' -- !! hook function not invoked. !!', ''); |
---|
30 | $param = null; |
---|
31 | $count = 0; |
---|
32 | |
---|
33 | foreach($callbacks as $callback) { |
---|
34 | |
---|
35 | add_action($hook, $callback); |
---|
36 | |
---|
37 | unset($param); |
---|
38 | $call = 'native invokation, standard parameter'; |
---|
39 | $param = 'original'; |
---|
40 | $called = 0; |
---|
41 | $callback($param); |
---|
42 | printf($mask, ++$count, $callback, $call, $param, $called_label[$called]); |
---|
43 | |
---|
44 | unset($param); |
---|
45 | $call = 'native invokation, call-time reference parameter'; |
---|
46 | $param = 'original'; |
---|
47 | $called = 0; |
---|
48 | $callback(&$param); |
---|
49 | printf($mask, ++$count, $callback, $call, $param, $called_label[$called]); |
---|
50 | |
---|
51 | unset($param); |
---|
52 | $call = 'do_action(), standard parameter'; |
---|
53 | $param = 'original'; |
---|
54 | $called = 0; |
---|
55 | do_action($hook, $param); |
---|
56 | printf($mask, ++$count, $callback, $call, $param, $called_label[$called]); |
---|
57 | |
---|
58 | unset($param); |
---|
59 | $call = 'do_action(), call-time reference parameter'; |
---|
60 | $param = 'original'; |
---|
61 | $called = 0; |
---|
62 | do_action($hook, &$param); |
---|
63 | printf($mask, ++$count, $callback, $call, $param, $called_label[$called]); |
---|
64 | |
---|
65 | |
---|
66 | unset($param); |
---|
67 | $call = 'do_action_ref_array(), standard parameter'; |
---|
68 | $param = 'original'; |
---|
69 | $called = 0; |
---|
70 | do_action_ref_array($hook, array($param)); |
---|
71 | printf($mask, ++$count, $callback, $call, $param, $called_label[$called]); |
---|
72 | |
---|
73 | unset($param); |
---|
74 | $call = 'do_action_ref_array(), call-time reference parameter'; |
---|
75 | $param = 'original'; |
---|
76 | $called = 0; |
---|
77 | do_action_ref_array($hook, array(&$param)); |
---|
78 | printf($mask, ++$count, $callback, $call, $param, $called_label[$called]); |
---|
79 | |
---|
80 | remove_action($hook, $callback); |
---|
81 | unset($param); |
---|
82 | } |
---|
83 | |
---|
84 | die(); |
---|