Annotation of embedaddon/php/ext/standard/tests/array/sizeof_object2.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: Test sizeof() function : object functionality - objects without Countable interface
                      3: --FILE--
                      4: <?php
                      5: /* Prototype  : int sizeof($mixed var[, int $mode] )
                      6:  * Description: Counts an elements in an array. If Standard PHP library is installed,
                      7:  * it will return the properties of an object.
                      8:  * Source code: ext/standard/basic_functions.c
                      9:  * Alias to functions: count()
                     10:  */
                     11: 
                     12: echo "*** Testing sizeof() : object functionality ***\n";
                     13: 
                     14: echo "--- Testing sizeof() with objects which doesn't implement Countable interface ---\n";
                     15: 
                     16: // class without member
                     17: class test
                     18: { 
                     19:   // no members
                     20: }
                     21: 
                     22: // class with only members and with out member functions 
                     23: class test1
                     24: {
                     25:   public $member1;
                     26:   var $var1;
                     27:   private $member2;
                     28:   protected $member3;
                     29: 
                     30:   // no member functions
                     31: }
                     32: 
                     33: // class with only member functions
                     34: class test2
                     35: {
                     36:   // no data members 
                     37: 
                     38:   public function display()
                     39:   {
                     40:     echo " Class Name : test2\n";
                     41:   }
                     42: }
                     43: 
                     44: // child class which inherits parent test2
                     45: class child_test2 extends test2
                     46: {
                     47:   public $child_member1;
                     48:   private $child_member2;
                     49: }
                     50: 
                     51: // abstract class
                     52: abstract class abstract_class
                     53: {
                     54:   public $member1;
                     55:   private $member2;
                     56:  
                     57:   abstract protected function display();
                     58: }
                     59: 
                     60: // implement abstract 'abstract_class' class
                     61: class concrete_class extends abstract_class
                     62: {
                     63:   protected function display()
                     64:   {
                     65:     echo " class name is : concrete_class \n ";
                     66:   }
                     67: }
                     68: 
                     69: $objects = array (
                     70:   /* 1  */  new test(),
                     71:             new test1(),
                     72:             new test2(),
                     73:             new child_test2(),
                     74:   /* 5  */  new concrete_class()
                     75: );
                     76: 
                     77: $counter = 1;
                     78: for($i = 0; $i < count($objects); $i++)
                     79: {
                     80:   echo "-- Iteration $counter --\n";
                     81:   $var = $objects[$i];
                     82: 
                     83:   echo "Default Mode: ";
                     84:   var_dump( sizeof($var) );
                     85:   echo "\n";
                     86:   
                     87:   echo "COUNT_NORMAL Mode: ";
                     88:   var_dump( sizeof($var, COUNT_NORMAL) );
                     89:   echo "\n";
                     90: 
                     91:   echo "COUNT_RECURSIVE Mode: ";
                     92:   var_dump( sizeof($var, COUNT_RECURSIVE) );
                     93:   echo "\n";
                     94:  
                     95:   $counter++;
                     96: }
                     97: 
                     98: echo "Done";
                     99: ?>
                    100: --EXPECTF--
                    101: *** Testing sizeof() : object functionality ***
                    102: --- Testing sizeof() with objects which doesn't implement Countable interface ---
                    103: -- Iteration 1 --
                    104: Default Mode: int(1)
                    105: 
                    106: COUNT_NORMAL Mode: int(1)
                    107: 
                    108: COUNT_RECURSIVE Mode: int(1)
                    109: 
                    110: -- Iteration 2 --
                    111: Default Mode: int(1)
                    112: 
                    113: COUNT_NORMAL Mode: int(1)
                    114: 
                    115: COUNT_RECURSIVE Mode: int(1)
                    116: 
                    117: -- Iteration 3 --
                    118: Default Mode: int(1)
                    119: 
                    120: COUNT_NORMAL Mode: int(1)
                    121: 
                    122: COUNT_RECURSIVE Mode: int(1)
                    123: 
                    124: -- Iteration 4 --
                    125: Default Mode: int(1)
                    126: 
                    127: COUNT_NORMAL Mode: int(1)
                    128: 
                    129: COUNT_RECURSIVE Mode: int(1)
                    130: 
                    131: -- Iteration 5 --
                    132: Default Mode: int(1)
                    133: 
                    134: COUNT_NORMAL Mode: int(1)
                    135: 
                    136: COUNT_RECURSIVE Mode: int(1)
                    137: 
                    138: Done

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