1--TEST--
2Test is_object() function
3--FILE--
4<?php
5echo "*** Testing is_object() with valid objects ***\n";
6
7// class with no members
8class foo
9{
10// no members
11}
12
13// abstract class
14abstract class abstractClass
15{
16  abstract protected function getClassName();
17  public function printClassName () {
18    echo $this->getClassName() . "\n";
19  }
20}
21
22// implement abstract class
23class concreteClass extends abstractClass
24{
25  protected function getClassName() {
26    return "concreteClass";
27  }
28}
29
30// interface class
31interface IValue
32{
33   public function setVal ($name, $val);
34   public function dumpVal ();
35}
36
37// implement the interface
38class Value implements IValue
39{
40  private $vars = array ();
41
42  public function setVal ( $name, $val ) {
43    $this->vars[$name] = $val;
44  }
45
46  public function dumpVal () {
47    var_dump ( $vars );
48  }
49}
50
51// a gereral class
52class myClass
53{
54  var       $foo_object;
55  public    $public_var;
56  public    $public_var1;
57  private   $private_var;
58  protected $protected_var;
59
60  function __construct ( ) {
61    $this->foo_object = new foo();
62    $this->public_var = 10;
63    $this->public_var1 = new foo();
64    $this->private_var = new foo();
65    $this->protected_var = new foo();
66  }
67}
68
69// create a object of each class defined above
70$myClass_object = new myClass();
71$foo_object = new foo();
72$Value_object = new Value();
73$concreteClass_object = new concreteClass();
74
75$valid_objects = array(
76  new stdclass,
77  new foo,
78  new concreteClass,
79  new Value,
80  new myClass,
81  $myClass_object,
82  $myClass_object->foo_object,
83  $myClass_object->public_var1,
84  $foo_object,
85  $Value_object,
86  $concreteClass_object
87);
88
89/* loop to check that is_object() recognizes different
90   objects, expected output: bool(true) */
91$loop_counter = 1;
92foreach ($valid_objects as $object ) {
93  echo "-- Iteration $loop_counter --\n"; $loop_counter++;
94  var_dump( is_object($object) );
95}
96
97echo "\n*** Testing is_object() on non object types ***\n";
98
99// get a resource type variable
100$fp = fopen (__FILE__, "r");
101$dfp = opendir ( __DIR__ );
102
103// unset object
104$unset_object = new foo();
105unset ($unset_object);
106
107// other types in a array
108$not_objects = array (
109  0,
110  -1,
111  0.1,
112  -10.0000000000000000005,
113  10.5e+5,
114  0xFF,
115  0123,
116  $fp,  // resource
117  $dfp,
118  array(),
119  array("string"),
120  "0",
121  "1",
122  "",
123  true,
124  NULL,
125  null,
126  @$unset_object, // unset object
127  @$undefined_var, // undefined variable
128);
129/* loop through the $not_objects to see working of
130   is_object() on non object types, expected output: bool(false) */
131$loop_counter = 1;
132foreach ($not_objects as $type ) {
133  echo "-- Iteration $loop_counter --\n"; $loop_counter++;
134  var_dump( is_object($type) );
135}
136
137echo "Done\n";
138
139// close the resources used
140fclose($fp);
141closedir($dfp);
142
143?>
144--EXPECT--
145*** Testing is_object() with valid objects ***
146-- Iteration 1 --
147bool(true)
148-- Iteration 2 --
149bool(true)
150-- Iteration 3 --
151bool(true)
152-- Iteration 4 --
153bool(true)
154-- Iteration 5 --
155bool(true)
156-- Iteration 6 --
157bool(true)
158-- Iteration 7 --
159bool(true)
160-- Iteration 8 --
161bool(true)
162-- Iteration 9 --
163bool(true)
164-- Iteration 10 --
165bool(true)
166-- Iteration 11 --
167bool(true)
168
169*** Testing is_object() on non object types ***
170-- Iteration 1 --
171bool(false)
172-- Iteration 2 --
173bool(false)
174-- Iteration 3 --
175bool(false)
176-- Iteration 4 --
177bool(false)
178-- Iteration 5 --
179bool(false)
180-- Iteration 6 --
181bool(false)
182-- Iteration 7 --
183bool(false)
184-- Iteration 8 --
185bool(false)
186-- Iteration 9 --
187bool(false)
188-- Iteration 10 --
189bool(false)
190-- Iteration 11 --
191bool(false)
192-- Iteration 12 --
193bool(false)
194-- Iteration 13 --
195bool(false)
196-- Iteration 14 --
197bool(false)
198-- Iteration 15 --
199bool(false)
200-- Iteration 16 --
201bool(false)
202-- Iteration 17 --
203bool(false)
204-- Iteration 18 --
205bool(false)
206-- Iteration 19 --
207bool(false)
208Done
209