Annotation of embedaddon/php/ext/standard/tests/general_functions/is_object.phpt, revision 1.1

1.1     ! misho       1: --TEST--
        !             2: Test is_object() function
        !             3: --FILE--
        !             4: <?php
        !             5: /* Prototype: bool is_object ( mixed $var );
        !             6:  * Description: Finds whether the given variable is an object  
        !             7:  */
        !             8: 
        !             9: echo "*** Testing is_object() with valid objects ***\n";
        !            10: 
        !            11: // class with no members
        !            12: class foo
        !            13: {
        !            14: // no members 
        !            15: }
        !            16: 
        !            17: // abstract class
        !            18: abstract class abstractClass
        !            19: {
        !            20:   abstract protected function getClassName();
        !            21:   public function printClassName () {
        !            22:     echo $this->getClassName() . "\n";
        !            23:   }
        !            24: }
        !            25: 
        !            26: // implement abstract class
        !            27: class concreteClass extends abstractClass
        !            28: {
        !            29:   protected function getClassName() {
        !            30:     return "concreteClass";
        !            31:   }
        !            32: }
        !            33: 
        !            34: // interface class 
        !            35: interface IValue
        !            36: {
        !            37:    public function setVal ($name, $val); 
        !            38:    public function dumpVal ();
        !            39: }
        !            40: 
        !            41: // implement the interface
        !            42: class Value implements IValue
        !            43: {
        !            44:   private $vars = array ();
        !            45:   
        !            46:   public function setVal ( $name, $val ) {
        !            47:     $this->vars[$name] = $val;
        !            48:   }
        !            49:   
        !            50:   public function dumpVal () {
        !            51:     var_dump ( $vars );
        !            52:   }
        !            53: }
        !            54: 
        !            55: // a gereral class 
        !            56: class myClass 
        !            57: {
        !            58:   var       $foo_object;
        !            59:   public    $public_var;
        !            60:   public    $public_var1;
        !            61:   private   $private_var;
        !            62:   protected $protected_var;
        !            63: 
        !            64:   function myClass ( ) {
        !            65:     $this->foo_object = new foo();
        !            66:     $this->public_var = 10;
        !            67:     $this->public_var1 = new foo();
        !            68:     $this->private_var = new foo();
        !            69:     $this->proected_var = new foo();
        !            70:   }  
        !            71: }
        !            72: 
        !            73: // create a object of each class defined above
        !            74: $myClass_object = new myClass();
        !            75: $foo_object = new foo();
        !            76: $Value_object = new Value();
        !            77: $concreteClass_object = new concreteClass();
        !            78: 
        !            79: $valid_objects = array(
        !            80:   new stdclass,
        !            81:   new foo,
        !            82:   new concreteClass,
        !            83:   new Value,
        !            84:   new myClass,
        !            85:   $myClass_object,
        !            86:   $myClass_object->foo_object,
        !            87:   $myClass_object->public_var1,
        !            88:   $foo_object,
        !            89:   $Value_object,
        !            90:   $concreteClass_object
        !            91: ); 
        !            92:                   
        !            93: /* loop to check that is_object() recognizes different 
        !            94:    objects, expected output: bool(true) */
        !            95: $loop_counter = 1;
        !            96: foreach ($valid_objects as $object ) {
        !            97:   echo "-- Iteration $loop_counter --\n"; $loop_counter++;
        !            98:   var_dump( is_object($object) );
        !            99: }
        !           100: 
        !           101: echo "\n*** Testing is_object() on non object types ***\n";
        !           102: 
        !           103: // get a resource type variable
        !           104: $fp = fopen (__FILE__, "r");
        !           105: $dfp = opendir ( dirname(__FILE__) );
        !           106: 
        !           107: // unset object 
        !           108: $unset_object = new foo();
        !           109: unset ($unset_object);
        !           110: 
        !           111: // other types in a array 
        !           112: $not_objects = array (
        !           113:   0,
        !           114:   -1,
        !           115:   0.1,
        !           116:   -10.0000000000000000005,
        !           117:   10.5e+5,
        !           118:   0xFF,
        !           119:   0123,
        !           120:   $fp,  // resource
        !           121:   $dfp,
        !           122:   array(),
        !           123:   array("string"),
        !           124:   "0",
        !           125:   "1",
        !           126:   "",
        !           127:   true,
        !           128:   NULL,
        !           129:   null,
        !           130:   @$unset_object, // unset object
        !           131:   @$undefined_var, // undefined variable
        !           132: );
        !           133: /* loop through the $not_objects to see working of 
        !           134:    is_object() on non object types, expected output: bool(false) */
        !           135: $loop_counter = 1;
        !           136: foreach ($not_objects as $type ) {
        !           137:   echo "-- Iteration $loop_counter --\n"; $loop_counter++;
        !           138:   var_dump( is_object($type) );
        !           139: }
        !           140: 
        !           141: echo "\n*** Testing error conditions ***\n";
        !           142: //Zero argument
        !           143: var_dump( is_object() );
        !           144: 
        !           145: //arguments more than expected 
        !           146: var_dump( is_object($myClass_object, $myClass_object) );
        !           147:  
        !           148: echo "Done\n";
        !           149: 
        !           150: // close the resources used
        !           151: fclose($fp);
        !           152: closedir($dfp);
        !           153: 
        !           154: ?>
        !           155: --EXPECTF--
        !           156: *** Testing is_object() with valid objects ***
        !           157: -- Iteration 1 --
        !           158: bool(true)
        !           159: -- Iteration 2 --
        !           160: bool(true)
        !           161: -- Iteration 3 --
        !           162: bool(true)
        !           163: -- Iteration 4 --
        !           164: bool(true)
        !           165: -- Iteration 5 --
        !           166: bool(true)
        !           167: -- Iteration 6 --
        !           168: bool(true)
        !           169: -- Iteration 7 --
        !           170: bool(true)
        !           171: -- Iteration 8 --
        !           172: bool(true)
        !           173: -- Iteration 9 --
        !           174: bool(true)
        !           175: -- Iteration 10 --
        !           176: bool(true)
        !           177: -- Iteration 11 --
        !           178: bool(true)
        !           179: 
        !           180: *** Testing is_object() on non object types ***
        !           181: -- Iteration 1 --
        !           182: bool(false)
        !           183: -- Iteration 2 --
        !           184: bool(false)
        !           185: -- Iteration 3 --
        !           186: bool(false)
        !           187: -- Iteration 4 --
        !           188: bool(false)
        !           189: -- Iteration 5 --
        !           190: bool(false)
        !           191: -- Iteration 6 --
        !           192: bool(false)
        !           193: -- Iteration 7 --
        !           194: bool(false)
        !           195: -- Iteration 8 --
        !           196: bool(false)
        !           197: -- Iteration 9 --
        !           198: bool(false)
        !           199: -- Iteration 10 --
        !           200: bool(false)
        !           201: -- Iteration 11 --
        !           202: bool(false)
        !           203: -- Iteration 12 --
        !           204: bool(false)
        !           205: -- Iteration 13 --
        !           206: bool(false)
        !           207: -- Iteration 14 --
        !           208: bool(false)
        !           209: -- Iteration 15 --
        !           210: bool(false)
        !           211: -- Iteration 16 --
        !           212: bool(false)
        !           213: -- Iteration 17 --
        !           214: bool(false)
        !           215: -- Iteration 18 --
        !           216: bool(false)
        !           217: -- Iteration 19 --
        !           218: bool(false)
        !           219: 
        !           220: *** Testing error conditions ***
        !           221: 
        !           222: Warning: is_object() expects exactly 1 parameter, 0 given in %s on line %d
        !           223: bool(false)
        !           224: 
        !           225: Warning: is_object() expects exactly 1 parameter, 2 given in %s on line %d
        !           226: bool(false)
        !           227: Done

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