123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434 |
- --TEST--
- Test array_fill() function : usage variations - various object values for 'val' argument
- --SKIPIF--
- <?php if (version_compare(zend_version(), '2.4.0', '>=')) die('skip ZendEngine 2.3 or below needed'); ?>
- --FILE--
- <?php
- /* Prototype : array array_fill(int $start_key, int $num, mixed $val)
- * Description: Create an array containing num elements starting with index start_key each initialized to val
- * Source code: ext/standard/array.c
- */
- /*
- * testing array_fill() by passing various object values for 'val' argument
- */
- echo "*** Testing array_fill() : usage variations ***\n";
- // Initialise function arguments not being substituted
- $start_key = 0;
- $num = 2;
- // class without a member
- class Test
- {
- }
- //class with public member, static member , constant and consturctor to initialize the public member
- class Test1
- {
- const test1_constant = "test1";
- public static $test1_static = 0;
- public $member1;
- var $var1 = 30;
- var $var2;
- function __construct($value1 , $value2)
- {
- $this->member1 = $value1;
- $this->var2 = $value2;
- }
- }
- // child class which inherits parent class test1
- class Child_test1 extends Test1
- {
- public $member2;
- function __construct($value1 , $value2 , $value3)
- {
- parent::__construct($value1 , $value2);
- $this->member2 = $value3;
- }
- }
- //class with private member, static member, constant and constructor to initialize the private member
- class Test2
- {
- const test2_constant = "test2";
- public static $test2_static = 0;
- private $member1;
- var $var1 = 30;
- var $var2;
- function __construct($value1 , $value2)
- {
- $this->member1 = $value1;
- $this->var2 = $value2;
- }
- }
- // child class which inherits parent class test2
- class Child_test2 extends Test2
- {
- private $member1;
- function __construct($value1 , $value2 , $value3)
- {
- parent::__construct($value1 , $value2);
- $this->member1 = $value3;
- }
- }
- // class with protected member, static member, constant and consturctor to initialize the protected member
- class Test3
- {
- const test3_constant = "test3";
- public static $test3_static = 0;
- protected $member1;
- var $var1 = 30;
- var $var2;
- function __construct($value1 , $value2)
- {
- $this->member1 = $value1;
- $this->var2 = $value2;
- }
- }
- // child class which inherits parent class test3
- class Child_test3 extends Test3
- {
- protected $member1;
- function __construct($value1 , $value2 , $value3)
- {
- parent::__construct($value1 , $value2);
- $this->member1 = $value3;
- }
- }
- // class with public, private, protected members, static, constant members and constructor to initialize all the members
- class Test4
- {
- const test4_constant = "test4";
- public static $test4_static = 0;
- public $member1;
- private $member2;
- protected $member3;
- function __construct($value1 , $value2 , $value3)
- {
- $this->member1 = $value1;
- $this->member2 = $value2;
- $this->member3 = $value3;
- }
- }
- // child class which inherits parent class test4
- class Child_test4 extends Test4
- {
- var $var1;
-
- function __construct($value1 , $value2 , $value3 , $value4)
- {
- parent::__construct($value1 , $value2 , $value3);
- $this->var1 = $value4;
- }
- }
- // abstract class with public, private, protected members
- abstract class AbstractClass
- {
- public $member1;
- private $member2;
- protected $member3;
- var $var1 = 30;
-
- abstract protected function display();
- }
- // implement abstract 'AbstractClass' class
- class ConcreteClass1 extends AbstractClass
- {
- protected function display()
- {
- echo "class name is ConcreteClass1 \n";
- }
- }
- // declarationn of the interface 'iTemplate'
- interface iTemplate
- {
- public function display();
- }
- // implement the interface 'iTemplate'
- class Template1 implements iTemplate
- {
- public function display()
- {
- echo "class name is Template1\n";
- }
- }
- //array of object values for 'val' argument
- $objects = array(
-
- /* 1 */ new Test(),
- new Test1(100 , 101),
- new Child_test1(100 , 101 , 102),
- new Test2(100 , 101),
- /* 5 */ new Child_test2(100 , 101 , 102),
- new Test3(100 , 101),
- new Child_test3(100 , 101 , 102),
- new Test4( 100 , 101 , 102),
- new Child_test4(100 , 101 , 102 , 103),
- new ConcreteClass1(),
- /* 11 */ new Template1()
- );
- // loop through each element of the array for 'val' argument
- // check the working of array_fill()
- echo "--- Testing array_fill() with different object values for 'val' argument ---\n";
- $counter = 1;
- for($index = 0; $index < count($objects); $index ++)
- {
- echo "-- Iteration $counter --\n";
- $val = $objects[$index];
- var_dump( array_fill($start_key,$num,$val) );
- $counter++;
- }
- echo "Done";
- ?>
- --EXPECTF--
- *** Testing array_fill() : usage variations ***
- --- Testing array_fill() with different object values for 'val' argument ---
- -- Iteration 1 --
- array(2) {
- [0]=>
- object(Test)#%d (0) {
- }
- [1]=>
- object(Test)#%d (0) {
- }
- }
- -- Iteration 2 --
- array(2) {
- [0]=>
- object(Test1)#%d (3) {
- ["member1"]=>
- int(100)
- ["var1"]=>
- int(30)
- ["var2"]=>
- int(101)
- }
- [1]=>
- object(Test1)#%d (3) {
- ["member1"]=>
- int(100)
- ["var1"]=>
- int(30)
- ["var2"]=>
- int(101)
- }
- }
- -- Iteration 3 --
- array(2) {
- [0]=>
- object(Child_test1)#%d (4) {
- ["member2"]=>
- int(102)
- ["member1"]=>
- int(100)
- ["var1"]=>
- int(30)
- ["var2"]=>
- int(101)
- }
- [1]=>
- object(Child_test1)#%d (4) {
- ["member2"]=>
- int(102)
- ["member1"]=>
- int(100)
- ["var1"]=>
- int(30)
- ["var2"]=>
- int(101)
- }
- }
- -- Iteration 4 --
- array(2) {
- [0]=>
- object(Test2)#%d (3) {
- ["member1":"Test2":private]=>
- int(100)
- ["var1"]=>
- int(30)
- ["var2"]=>
- int(101)
- }
- [1]=>
- object(Test2)#%d (3) {
- ["member1":"Test2":private]=>
- int(100)
- ["var1"]=>
- int(30)
- ["var2"]=>
- int(101)
- }
- }
- -- Iteration 5 --
- array(2) {
- [0]=>
- object(Child_test2)#%d (4) {
- ["member1":"Child_test2":private]=>
- int(102)
- ["member1":"Test2":private]=>
- int(100)
- ["var1"]=>
- int(30)
- ["var2"]=>
- int(101)
- }
- [1]=>
- object(Child_test2)#%d (4) {
- ["member1":"Child_test2":private]=>
- int(102)
- ["member1":"Test2":private]=>
- int(100)
- ["var1"]=>
- int(30)
- ["var2"]=>
- int(101)
- }
- }
- -- Iteration 6 --
- array(2) {
- [0]=>
- object(Test3)#%d (3) {
- ["member1":protected]=>
- int(100)
- ["var1"]=>
- int(30)
- ["var2"]=>
- int(101)
- }
- [1]=>
- object(Test3)#%d (3) {
- ["member1":protected]=>
- int(100)
- ["var1"]=>
- int(30)
- ["var2"]=>
- int(101)
- }
- }
- -- Iteration 7 --
- array(2) {
- [0]=>
- object(Child_test3)#%d (3) {
- ["member1":protected]=>
- int(102)
- ["var1"]=>
- int(30)
- ["var2"]=>
- int(101)
- }
- [1]=>
- object(Child_test3)#%d (3) {
- ["member1":protected]=>
- int(102)
- ["var1"]=>
- int(30)
- ["var2"]=>
- int(101)
- }
- }
- -- Iteration 8 --
- array(2) {
- [0]=>
- object(Test4)#%d (3) {
- ["member1"]=>
- int(100)
- ["member2":"Test4":private]=>
- int(101)
- ["member3":protected]=>
- int(102)
- }
- [1]=>
- object(Test4)#%d (3) {
- ["member1"]=>
- int(100)
- ["member2":"Test4":private]=>
- int(101)
- ["member3":protected]=>
- int(102)
- }
- }
- -- Iteration 9 --
- array(2) {
- [0]=>
- object(Child_test4)#%d (4) {
- ["var1"]=>
- int(103)
- ["member1"]=>
- int(100)
- ["member2":"Test4":private]=>
- int(101)
- ["member3":protected]=>
- int(102)
- }
- [1]=>
- object(Child_test4)#%d (4) {
- ["var1"]=>
- int(103)
- ["member1"]=>
- int(100)
- ["member2":"Test4":private]=>
- int(101)
- ["member3":protected]=>
- int(102)
- }
- }
- -- Iteration 10 --
- array(2) {
- [0]=>
- object(ConcreteClass1)#%d (4) {
- ["member1"]=>
- NULL
- ["member2":"AbstractClass":private]=>
- NULL
- ["member3":protected]=>
- NULL
- ["var1"]=>
- int(30)
- }
- [1]=>
- object(ConcreteClass1)#%d (4) {
- ["member1"]=>
- NULL
- ["member2":"AbstractClass":private]=>
- NULL
- ["member3":protected]=>
- NULL
- ["var1"]=>
- int(30)
- }
- }
- -- Iteration 11 --
- array(2) {
- [0]=>
- object(Template1)#%d (0) {
- }
- [1]=>
- object(Template1)#%d (0) {
- }
- }
- Done
|