1--TEST--
2assert() - variation  - test callback options using ini_get/ini_set/assert_options
3--INI--
4assert.active = 1
5assert.warning = 0
6assert.callback = f1
7assert.bail = 0
8assert.exception=0
9--FILE--
10<?php
11function f1()
12{
13    echo "f1 called\n";
14}
15function f2()
16{
17    echo "f2 called\n";
18}
19function f3()
20{
21    echo "f3 called\n";
22}
23class c1
24{
25    static function assert($file, $line, $unused, $desc)
26    {
27        echo "Class assertion failed $line, \"$desc\"\n";
28    }
29}
30echo "Initial values: assert_options(ASSERT_CALLBACK) => [".assert_options(ASSERT_CALLBACK)."]\n";
31echo "Initial values: ini.get(\"assert.callback\") => [".ini_get("assert.callback")."]\n";
32var_dump($r2=assert(0 != 0));
33echo"\n";
34
35echo "Change callback function using ini.set and test return value \n";
36var_dump($rv = ini_set("assert.callback","f2"));
37echo "assert_options(ASSERT_CALLBACK) => [".assert_options(ASSERT_CALLBACK)."]\n";
38echo "ini.get(\"assert.callback\") => [".ini_get("assert.callback")."]\n";
39var_dump($r2=assert(0 != 0));
40echo"\n";
41
42echo "Change callback function using assert_options and test return value \n";
43var_dump($rv=assert_options(ASSERT_CALLBACK, "f3"));
44echo "assert_options(ASSERT_CALLBACK) => [".assert_options(ASSERT_CALLBACK)."]\n";
45echo "ini.get(\"assert.callback\") => [".ini_get("assert.callback")."]\n";
46var_dump($r2=assert(0 != 0));
47echo"\n";
48
49
50echo "Reset the name of the callback routine to a class method and check that it works\n";
51var_dump($rc=assert_options(ASSERT_CALLBACK, "c1"));
52echo "assert_options(ASSERT_CALLBACK) => [".assert_options(ASSERT_CALLBACK)."]\n";
53echo "ini.get(\"assert.callback\") => [".ini_get("assert.callback")."]\n";
54var_dump($r2=assert(0 != 0));
55echo"\n";
56
57echo "Reset callback options to use a class method \n";
58var_dump($rc = assert_options(ASSERT_CALLBACK,array("c1","assert")));
59var_dump($rao=assert_options(ASSERT_CALLBACK));
60echo "ini.get(\"assert.callback\") => [".ini_get("assert.callback")."]\n\n";
61var_dump($r2=assert(0 != 0));
62echo"\n";
63
64echo "Reset callback options to use an object method \n";
65$o = new c1();
66var_dump($rc=assert_options(ASSERT_CALLBACK,array(&$o,"assert")));
67var_dump($rao=assert_options(ASSERT_CALLBACK));
68echo "ini.get(\"assert.callback\") => [".ini_get("assert.callback")."]\n\n";
69var_dump($r2=assert(0 != 0));
70echo"\n";
71
72echo "Set callback to something silly\n";
73assert_options(ASSERT_CALLBACK, 3.141);
74var_dump($rao = assert_options(ASSERT_CALLBACK));
75
76?>
77--EXPECT--
78Initial values: assert_options(ASSERT_CALLBACK) => [f1]
79Initial values: ini.get("assert.callback") => [f1]
80f1 called
81bool(false)
82
83Change callback function using ini.set and test return value
84string(2) "f1"
85assert_options(ASSERT_CALLBACK) => [f2]
86ini.get("assert.callback") => [f2]
87f2 called
88bool(false)
89
90Change callback function using assert_options and test return value
91string(2) "f2"
92assert_options(ASSERT_CALLBACK) => [f3]
93ini.get("assert.callback") => [f2]
94f3 called
95bool(false)
96
97Reset the name of the callback routine to a class method and check that it works
98string(2) "f3"
99assert_options(ASSERT_CALLBACK) => [c1]
100ini.get("assert.callback") => [f2]
101bool(false)
102
103Reset callback options to use a class method
104string(2) "c1"
105array(2) {
106  [0]=>
107  string(2) "c1"
108  [1]=>
109  string(6) "assert"
110}
111ini.get("assert.callback") => [f2]
112
113Class assertion failed 52, "assert(0 != 0)"
114bool(false)
115
116Reset callback options to use an object method
117array(2) {
118  [0]=>
119  string(2) "c1"
120  [1]=>
121  string(6) "assert"
122}
123array(2) {
124  [0]=>
125  &object(c1)#1 (0) {
126  }
127  [1]=>
128  string(6) "assert"
129}
130ini.get("assert.callback") => [f2]
131
132Class assertion failed 60, "assert(0 != 0)"
133bool(false)
134
135Set callback to something silly
136float(3.141)
137