1--TEST-- 2Test array_fill() function : usage variations - various object values for 'val' argument 3--FILE-- 4<?php 5/* Prototype : array array_fill(int $start_key, int $num, mixed $val) 6 * Description: Create an array containing num elements starting with index start_key each initialized to val 7 * Source code: ext/standard/array.c 8 */ 9 10/* 11 * testing array_fill() by passing various object values for 'val' argument 12 */ 13 14echo "*** Testing array_fill() : usage variations ***\n"; 15 16// Initialise function arguments not being substituted 17$start_key = 0; 18$num = 2; 19 20// class without a member 21class Test 22{ 23} 24 25//class with public member, static member , constant and consturctor to initialize the public member 26class Test1 27{ 28 const test1_constant = "test1"; 29 public static $test1_static = 0; 30 public $member1; 31 var $var1 = 30; 32 var $var2; 33 34 function __construct($value1 , $value2) 35 { 36 $this->member1 = $value1; 37 $this->var2 = $value2; 38 } 39} 40 41// child class which inherits parent class test1 42class Child_test1 extends Test1 43{ 44 public $member2; 45 46 function __construct($value1 , $value2 , $value3) 47 { 48 parent::__construct($value1 , $value2); 49 $this->member2 = $value3; 50 } 51} 52 53//class with private member, static member, constant and constructor to initialize the private member 54class Test2 55{ 56 const test2_constant = "test2"; 57 public static $test2_static = 0; 58 private $member1; 59 var $var1 = 30; 60 var $var2; 61 62 function __construct($value1 , $value2) 63 { 64 $this->member1 = $value1; 65 $this->var2 = $value2; 66 } 67} 68 69// child class which inherits parent class test2 70class Child_test2 extends Test2 71{ 72 private $member1; 73 74 function __construct($value1 , $value2 , $value3) 75 { 76 parent::__construct($value1 , $value2); 77 $this->member1 = $value3; 78 } 79} 80 81// class with protected member, static member, constant and consturctor to initialize the protected member 82class Test3 83{ 84 const test3_constant = "test3"; 85 public static $test3_static = 0; 86 protected $member1; 87 var $var1 = 30; 88 var $var2; 89 90 function __construct($value1 , $value2) 91 { 92 $this->member1 = $value1; 93 $this->var2 = $value2; 94 } 95} 96 97// child class which inherits parent class test3 98class Child_test3 extends Test3 99{ 100 protected $member1; 101 102 function __construct($value1 , $value2 , $value3) 103 { 104 parent::__construct($value1 , $value2); 105 $this->member1 = $value3; 106 } 107} 108 109// class with public, private, protected members, static, constant members and constructor to initialize all the members 110class Test4 111{ 112 const test4_constant = "test4"; 113 public static $test4_static = 0; 114 public $member1; 115 private $member2; 116 protected $member3; 117 118 function __construct($value1 , $value2 , $value3) 119 { 120 $this->member1 = $value1; 121 $this->member2 = $value2; 122 $this->member3 = $value3; 123 } 124} 125 126// child class which inherits parent class test4 127class Child_test4 extends Test4 128{ 129 var $var1; 130 131 function __construct($value1 , $value2 , $value3 , $value4) 132 { 133 parent::__construct($value1 , $value2 , $value3); 134 $this->var1 = $value4; 135 } 136} 137 138// abstract class with public, private, protected members 139abstract class AbstractClass 140{ 141 public $member1; 142 private $member2; 143 protected $member3; 144 var $var1 = 30; 145 146 abstract protected function display(); 147} 148 149// implement abstract 'AbstractClass' class 150class ConcreteClass1 extends AbstractClass 151{ 152 protected function display() 153 { 154 echo "class name is ConcreteClass1 \n"; 155 } 156} 157 158 159// declarationn of the interface 'iTemplate' 160interface iTemplate 161{ 162 public function display(); 163} 164 165// implement the interface 'iTemplate' 166class Template1 implements iTemplate 167{ 168 public function display() 169 { 170 echo "class name is Template1\n"; 171 } 172} 173 174//array of object values for 'val' argument 175$objects = array( 176 177 /* 1 */ new Test(), 178 new Test1(100 , 101), 179 new Child_test1(100 , 101 , 102), 180 new Test2(100 , 101), 181 /* 5 */ new Child_test2(100 , 101 , 102), 182 new Test3(100 , 101), 183 new Child_test3(100 , 101 , 102), 184 new Test4( 100 , 101 , 102), 185 new Child_test4(100 , 101 , 102 , 103), 186 new ConcreteClass1(), 187 /* 11 */ new Template1() 188); 189 190// loop through each element of the array for 'val' argument 191// check the working of array_fill() 192echo "--- Testing array_fill() with different object values for 'val' argument ---\n"; 193$counter = 1; 194for($index = 0; $index < count($objects); $index ++) 195{ 196 echo "-- Iteration $counter --\n"; 197 $val = $objects[$index]; 198 199 var_dump( array_fill($start_key,$num,$val) ); 200 201 $counter++; 202} 203 204echo "Done"; 205?> 206--EXPECTF-- 207*** Testing array_fill() : usage variations *** 208--- Testing array_fill() with different object values for 'val' argument --- 209-- Iteration 1 -- 210array(2) { 211 [0]=> 212 object(Test)#%d (0) { 213 } 214 [1]=> 215 object(Test)#%d (0) { 216 } 217} 218-- Iteration 2 -- 219array(2) { 220 [0]=> 221 object(Test1)#%d (3) { 222 ["member1"]=> 223 int(100) 224 ["var1"]=> 225 int(30) 226 ["var2"]=> 227 int(101) 228 } 229 [1]=> 230 object(Test1)#%d (3) { 231 ["member1"]=> 232 int(100) 233 ["var1"]=> 234 int(30) 235 ["var2"]=> 236 int(101) 237 } 238} 239-- Iteration 3 -- 240array(2) { 241 [0]=> 242 object(Child_test1)#%d (4) { 243 ["member2"]=> 244 int(102) 245 ["member1"]=> 246 int(100) 247 ["var1"]=> 248 int(30) 249 ["var2"]=> 250 int(101) 251 } 252 [1]=> 253 object(Child_test1)#%d (4) { 254 ["member2"]=> 255 int(102) 256 ["member1"]=> 257 int(100) 258 ["var1"]=> 259 int(30) 260 ["var2"]=> 261 int(101) 262 } 263} 264-- Iteration 4 -- 265array(2) { 266 [0]=> 267 object(Test2)#%d (3) { 268 ["member1":"Test2":private]=> 269 int(100) 270 ["var1"]=> 271 int(30) 272 ["var2"]=> 273 int(101) 274 } 275 [1]=> 276 object(Test2)#%d (3) { 277 ["member1":"Test2":private]=> 278 int(100) 279 ["var1"]=> 280 int(30) 281 ["var2"]=> 282 int(101) 283 } 284} 285-- Iteration 5 -- 286array(2) { 287 [0]=> 288 object(Child_test2)#%d (4) { 289 ["member1":"Child_test2":private]=> 290 int(102) 291 ["var1"]=> 292 int(30) 293 ["var2"]=> 294 int(101) 295 ["member1":"Test2":private]=> 296 int(100) 297 } 298 [1]=> 299 object(Child_test2)#%d (4) { 300 ["member1":"Child_test2":private]=> 301 int(102) 302 ["var1"]=> 303 int(30) 304 ["var2"]=> 305 int(101) 306 ["member1":"Test2":private]=> 307 int(100) 308 } 309} 310-- Iteration 6 -- 311array(2) { 312 [0]=> 313 object(Test3)#%d (3) { 314 ["member1":protected]=> 315 int(100) 316 ["var1"]=> 317 int(30) 318 ["var2"]=> 319 int(101) 320 } 321 [1]=> 322 object(Test3)#%d (3) { 323 ["member1":protected]=> 324 int(100) 325 ["var1"]=> 326 int(30) 327 ["var2"]=> 328 int(101) 329 } 330} 331-- Iteration 7 -- 332array(2) { 333 [0]=> 334 object(Child_test3)#%d (3) { 335 ["member1":protected]=> 336 int(102) 337 ["var1"]=> 338 int(30) 339 ["var2"]=> 340 int(101) 341 } 342 [1]=> 343 object(Child_test3)#%d (3) { 344 ["member1":protected]=> 345 int(102) 346 ["var1"]=> 347 int(30) 348 ["var2"]=> 349 int(101) 350 } 351} 352-- Iteration 8 -- 353array(2) { 354 [0]=> 355 object(Test4)#%d (3) { 356 ["member1"]=> 357 int(100) 358 ["member2":"Test4":private]=> 359 int(101) 360 ["member3":protected]=> 361 int(102) 362 } 363 [1]=> 364 object(Test4)#%d (3) { 365 ["member1"]=> 366 int(100) 367 ["member2":"Test4":private]=> 368 int(101) 369 ["member3":protected]=> 370 int(102) 371 } 372} 373-- Iteration 9 -- 374array(2) { 375 [0]=> 376 object(Child_test4)#%d (4) { 377 ["var1"]=> 378 int(103) 379 ["member1"]=> 380 int(100) 381 ["member2":"Test4":private]=> 382 int(101) 383 ["member3":protected]=> 384 int(102) 385 } 386 [1]=> 387 object(Child_test4)#%d (4) { 388 ["var1"]=> 389 int(103) 390 ["member1"]=> 391 int(100) 392 ["member2":"Test4":private]=> 393 int(101) 394 ["member3":protected]=> 395 int(102) 396 } 397} 398-- Iteration 10 -- 399array(2) { 400 [0]=> 401 object(ConcreteClass1)#%d (4) { 402 ["member1"]=> 403 NULL 404 ["member2":"AbstractClass":private]=> 405 NULL 406 ["member3":protected]=> 407 NULL 408 ["var1"]=> 409 int(30) 410 } 411 [1]=> 412 object(ConcreteClass1)#%d (4) { 413 ["member1"]=> 414 NULL 415 ["member2":"AbstractClass":private]=> 416 NULL 417 ["member3":protected]=> 418 NULL 419 ["var1"]=> 420 int(30) 421 } 422} 423-- Iteration 11 -- 424array(2) { 425 [0]=> 426 object(Template1)#%d (0) { 427 } 428 [1]=> 429 object(Template1)#%d (0) { 430 } 431} 432Done 433