1--TEST-- 2Test 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 12echo "*** Testing sizeof() : object functionality ***\n"; 13 14echo "--- Testing sizeof() with objects which doesn't implement Countable interface ---\n"; 15 16// class without member 17class test 18{ 19 // no members 20} 21 22// class with only members and with out member functions 23class 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 34class 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 45class child_test2 extends test2 46{ 47 public $child_member1; 48 private $child_member2; 49} 50 51// abstract class 52abstract class abstract_class 53{ 54 public $member1; 55 private $member2; 56 57 abstract protected function display(); 58} 59 60// implement abstract 'abstract_class' class 61class 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; 78for($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 98echo "Done"; 99?> 100--EXPECTF-- 101*** Testing sizeof() : object functionality *** 102--- Testing sizeof() with objects which doesn't implement Countable interface --- 103-- Iteration 1 -- 104Default Mode: 105Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d 106int(1) 107 108COUNT_NORMAL Mode: 109Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d 110int(1) 111 112COUNT_RECURSIVE Mode: 113Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d 114int(1) 115 116-- Iteration 2 -- 117Default Mode: 118Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d 119int(1) 120 121COUNT_NORMAL Mode: 122Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d 123int(1) 124 125COUNT_RECURSIVE Mode: 126Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d 127int(1) 128 129-- Iteration 3 -- 130Default Mode: 131Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d 132int(1) 133 134COUNT_NORMAL Mode: 135Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d 136int(1) 137 138COUNT_RECURSIVE Mode: 139Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d 140int(1) 141 142-- Iteration 4 -- 143Default Mode: 144Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d 145int(1) 146 147COUNT_NORMAL Mode: 148Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d 149int(1) 150 151COUNT_RECURSIVE Mode: 152Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d 153int(1) 154 155-- Iteration 5 -- 156Default Mode: 157Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d 158int(1) 159 160COUNT_NORMAL Mode: 161Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d 162int(1) 163 164COUNT_RECURSIVE Mode: 165Warning: sizeof(): Parameter must be an array or an object that implements Countable in %s on line %d 166int(1) 167 168Done 169