Annotation of embedaddon/php/ext/standard/tests/array/array_fill_object.phpt, revision 1.1.1.2

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>