Annotation of embedaddon/php/ext/standard/tests/strings/strval_error.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test strval() function : usage variations - error conditions
3: --FILE--
4: <?php
5: /* Prototype : string strval ( mixed $var )
6: * Description: Get the string value of a variable.
7: * Source code: ext/standard/string.c
8: */
9:
10: echo "*** Testing strval() : error conditions ***\n";
11:
12: error_reporting(E_ALL ^ E_NOTICE);
13:
14: class MyClass
15: {
16: // no toString() method defined
17: }
18:
19: $string = "Hello";
20: $extra_arg = 10;
21:
22: //Test strval with one more than the expected number of arguments
23: echo "\n-- Testing strval() function with more than expected no. of arguments --\n";
24: var_dump( strval($string, $extra_arg) );
25:
26: // Testing strval with one less than the expected number of arguments
27: echo "\n-- Testing strval() function with less than expected no. of arguments --\n";
28: var_dump( strval() );
29:
30: // Testing strval with a object which has no toString() method
31: echo "\n-- Testing strval() function with object which has not toString() method --\n";
32: var_dump( strval(new MyClass()) );
33:
34: ?>
35: ===DONE===
36: --EXPECTF--
37: *** Testing strval() : error conditions ***
38:
39: -- Testing strval() function with more than expected no. of arguments --
40:
41: Warning: strval() expects exactly 1 parameter, 2 given in %s on line %d
42: NULL
43:
44: -- Testing strval() function with less than expected no. of arguments --
45:
46: Warning: strval() expects exactly 1 parameter, 0 given in %s on line %d
47: NULL
48:
49: -- Testing strval() function with object which has not toString() method --
50:
51: Catchable fatal error: Object of class MyClass could not be converted to string in %s on line %d
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>