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\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";
54try {
55    var_dump($r2=assert(0 != 0));
56} catch (Error $e) {
57    echo $e->getMessage(), "\n";
58}
59echo"\n";
60
61echo "Reset callback options to use a class method\n";
62var_dump($rc = assert_options(ASSERT_CALLBACK,array("c1","assert")));
63var_dump($rao=assert_options(ASSERT_CALLBACK));
64echo "ini.get(\"assert.callback\") => [".ini_get("assert.callback")."]\n\n";
65var_dump($r2=assert(0 != 0));
66echo"\n";
67
68echo "Reset callback options to use an object method\n";
69$o = new c1();
70var_dump($rc=assert_options(ASSERT_CALLBACK,array(&$o,"assert")));
71var_dump($rao=assert_options(ASSERT_CALLBACK));
72echo "ini.get(\"assert.callback\") => [".ini_get("assert.callback")."]\n\n";
73var_dump($r2=assert(0 != 0));
74echo"\n";
75
76echo "Set callback to something silly\n";
77assert_options(ASSERT_CALLBACK, 3.141);
78var_dump($rao = assert_options(ASSERT_CALLBACK));
79
80?>
81--EXPECTF--
82Deprecated: PHP Startup: assert.warning INI setting is deprecated in Unknown on line 0
83
84Deprecated: PHP Startup: assert.callback INI setting is deprecated in Unknown on line 0
85
86Deprecated: PHP Startup: assert.exception INI setting is deprecated in Unknown on line 0
87
88Deprecated: Constant ASSERT_CALLBACK is deprecated in %s on line %d
89
90Deprecated: Function assert_options() is deprecated in %s on line %d
91Initial values: assert_options(ASSERT_CALLBACK) => [f1]
92Initial values: ini.get("assert.callback") => [f1]
93f1 called
94bool(false)
95
96Change callback function using ini.set and test return value
97
98Deprecated: ini_set(): assert.callback INI setting is deprecated in %s on line %d
99string(2) "f1"
100
101Deprecated: Constant ASSERT_CALLBACK is deprecated in %s on line %d
102
103Deprecated: Function assert_options() is deprecated in %s on line %d
104assert_options(ASSERT_CALLBACK) => [f2]
105ini.get("assert.callback") => [f2]
106f2 called
107bool(false)
108
109Change callback function using assert_options and test return value
110
111Deprecated: Constant ASSERT_CALLBACK is deprecated in %s on line %d
112
113Deprecated: Function assert_options() is deprecated in %s on line %d
114string(2) "f2"
115
116Deprecated: Constant ASSERT_CALLBACK is deprecated in %s on line %d
117
118Deprecated: Function assert_options() is deprecated in %s on line %d
119assert_options(ASSERT_CALLBACK) => [f3]
120ini.get("assert.callback") => [f2]
121f3 called
122bool(false)
123
124Reset the name of the callback routine to a class method
125
126Deprecated: Constant ASSERT_CALLBACK is deprecated in %s on line %d
127
128Deprecated: Function assert_options() is deprecated in %s on line %d
129string(2) "f3"
130
131Deprecated: Constant ASSERT_CALLBACK is deprecated in %s on line %d
132
133Deprecated: Function assert_options() is deprecated in %s on line %d
134assert_options(ASSERT_CALLBACK) => [c1]
135ini.get("assert.callback") => [f2]
136Invalid callback c1, function "c1" not found or invalid function name
137
138Reset callback options to use a class method
139
140Deprecated: Constant ASSERT_CALLBACK is deprecated in %s on line %d
141
142Deprecated: Function assert_options() is deprecated in %s on line %d
143string(2) "c1"
144
145Deprecated: Constant ASSERT_CALLBACK is deprecated in %s on line %d
146
147Deprecated: Function assert_options() is deprecated in %s on line %d
148array(2) {
149  [0]=>
150  string(2) "c1"
151  [1]=>
152  string(6) "assert"
153}
154ini.get("assert.callback") => [f2]
155
156Class assertion failed 56, "assert(0 != 0)"
157bool(false)
158
159Reset callback options to use an object method
160
161Deprecated: Constant ASSERT_CALLBACK is deprecated in %s on line %d
162
163Deprecated: Function assert_options() is deprecated in %s on line %d
164array(2) {
165  [0]=>
166  string(2) "c1"
167  [1]=>
168  string(6) "assert"
169}
170
171Deprecated: Constant ASSERT_CALLBACK is deprecated in %s on line %d
172
173Deprecated: Function assert_options() is deprecated in %s on line %d
174array(2) {
175  [0]=>
176  &object(c1)#2 (0) {
177  }
178  [1]=>
179  string(6) "assert"
180}
181ini.get("assert.callback") => [f2]
182
183Class assertion failed 64, "assert(0 != 0)"
184bool(false)
185
186Set callback to something silly
187
188Deprecated: Constant ASSERT_CALLBACK is deprecated in %s on line %d
189
190Deprecated: Function assert_options() is deprecated in %s on line %d
191
192Deprecated: Constant ASSERT_CALLBACK is deprecated in %s on line %d
193
194Deprecated: Function assert_options() is deprecated in %s on line %d
195float(3.141)
196