Annotation of embedaddon/php/ext/standard/tests/general_functions/is_resource_basic.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test is_resource() function : basic functionality
3: --FILE--
4: <?php
5: /* Prototype : bool is_resource ( mixed $var )
6: * Description: Finds whether a variable is a resource
7: * Source code: ext/standard/type.c
8: */
9:
10: echo "*** Testing is_resource() : basic functionality ***\n";
11:
12: class Hello {
13: public function SayHello($arg) {
14: echo "Hello\n";
15: }
16: }
17:
18:
19: $vars = array(
20: false,
21: true,
22: 10,
23: 10.5,
24: "Helo World",
25: array(1,2,3,4,5),
26: NULL,
27: new Hello());
28:
29: $types = array(
30: "bool=false",
31: "bool=true",
32: "integer",
33: "double",
34: "string",
35: "array",
36: "NULL",
37: "object");
38:
39: echo "\nNon-resource type cases\n";
40:
41: for ($i=0; $i < count($vars); $i++) {
42: if (is_resource($vars[$i])) {
43: echo $types[$i]. " test returns TRUE\n";
44: } else {
45: echo $types[$i]. " test returns FALSE\n";
46: }
47: }
48:
49: $res = fopen(__FILE__, "r");
50: echo "\nResource type..var_dump after file open returns\n";
51: var_dump($res);
52: echo "Resource type..after file open is_resource() returns";
53: if (is_resource($res)) {
54: echo " TRUE\n";
55: } else {
56: echo " FALSE\n";
57: }
58:
59: fclose($res);
60: echo "\nResource type..var_dump after file close returns\n";
61: var_dump($res);
62: echo "Resource type..after file close is_resource() returns";
63: if (is_resource($res)) {
64: echo " TRUE\n";
65: } else {
66: echo " FALSE\n";
67: }
68:
69:
70: ?>
71: ===DONE===
72: --EXPECTF--
73: *** Testing is_resource() : basic functionality ***
74:
75: Non-resource type cases
76: bool=false test returns FALSE
77: bool=true test returns FALSE
78: integer test returns FALSE
79: double test returns FALSE
80: string test returns FALSE
81: array test returns FALSE
82: NULL test returns FALSE
83: object test returns FALSE
84:
85: Resource type..var_dump after file open returns
86: resource(%d) of type (%s)
87: Resource type..after file open is_resource() returns TRUE
88:
89: Resource type..var_dump after file close returns
90: resource(%d) of type (Unknown)
91: Resource type..after file close is_resource() returns FALSE
92: ===DONE===
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>