summaryrefslogtreecommitdiff
path: root/ext/standard/tests/general_functions/is_resource_basic.phpt
blob: 75f4e4a8d8b7e366116ab3e5b36fe5b42bfdb643 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
--TEST--
Test is_resource() function : basic functionality
--FILE--
<?php
/* Prototype  : bool is_resource  ( mixed $var  )
 * Description:  Finds whether a variable is a resource
 * Source code: ext/standard/type.c
 */

echo "*** Testing is_resource() : basic functionality ***\n";

class Hello {
  public function SayHello($arg) {
  	echo "Hello\n";
  }
}


$vars = array(
	false,
	true,
	10,
	10.5,
	"Helo World",
	array(1,2,3,4,5),
	NULL,
	new Hello());

$types = array(
	"bool=false",
	"bool=true",
	"integer",
	"double",
	"string",
	"array",
	"NULL",
	"object");

echo "\nNon-resource type cases\n";

for ($i=0; $i < count($vars); $i++) {
	if (is_resource($vars[$i])) {
		echo $types[$i]. " test returns TRUE\n";
	} else {
		echo $types[$i]. " test returns FALSE\n";
	}
}

$res = fopen(__FILE__, "r");
echo "\nResource type..var_dump after file open returns\n";
var_dump($res);
echo "Resource type..after file open  is_resource() returns";
if (is_resource($res)) {
	echo " TRUE\n";
} else {
	echo " FALSE\n";
}

fclose($res);
echo "\nResource type..var_dump after file close returns\n";
var_dump($res);
echo "Resource type..after file close is_resource() returns";
if (is_resource($res)) {
	echo " TRUE\n";
} else {
	echo " FALSE\n";
}


?>
===DONE===
--EXPECTF--
*** Testing is_resource() : basic functionality ***

Non-resource type cases
bool=false test returns FALSE
bool=true test returns FALSE
integer test returns FALSE
double test returns FALSE
string test returns FALSE
array test returns FALSE
NULL test returns FALSE
object test returns FALSE

Resource type..var_dump after file open returns
resource(%d) of type (%s)
Resource type..after file open  is_resource() returns TRUE

Resource type..var_dump after file close returns
resource(%d) of type (Unknown)
Resource type..after file close is_resource() returns FALSE
===DONE===