Annotation of embedaddon/php/ext/reflection/tests/ReflectionProperty_basic1.phpt, revision 1.1

1.1     ! misho       1: --TEST--
        !             2: Test usage of ReflectionProperty methods __toString(), export(), getName(), isPublic(), isPrivate(), isProtected(), isStatic(), getValue() and setValue().
        !             3: --FILE--
        !             4: <?php
        !             5: 
        !             6: function reflectProperty($class, $property) {
        !             7:     $propInfo = new ReflectionProperty($class, $property);
        !             8:     echo "**********************************\n";
        !             9:     echo "Reflecting on property $class::$property\n\n";
        !            10:     echo "__toString():\n";
        !            11:     var_dump($propInfo->__toString());
        !            12:     echo "export():\n";
        !            13:     var_dump(ReflectionProperty::export($class, $property, true));
        !            14:     echo "export():\n";
        !            15:     var_dump(ReflectionProperty::export($class, $property, false));
        !            16:     echo "getName():\n";
        !            17:     var_dump($propInfo->getName());
        !            18:     echo "isPublic():\n";
        !            19:     var_dump($propInfo->isPublic());
        !            20:     echo "isPrivate():\n";
        !            21:     var_dump($propInfo->isPrivate());
        !            22:     echo "isProtected():\n";
        !            23:     var_dump($propInfo->isProtected());
        !            24:     echo "isStatic():\n";
        !            25:     var_dump($propInfo->isStatic());
        !            26:     $instance = new $class();
        !            27:     if ($propInfo->isPublic()) {
        !            28:         echo "getValue():\n";
        !            29:         var_dump($propInfo->getValue($instance));
        !            30:         $propInfo->setValue($instance, "NewValue");
        !            31:         echo "getValue() after a setValue():\n";
        !            32:         var_dump($propInfo->getValue($instance));
        !            33:     }
        !            34:     echo "\n**********************************\n";
        !            35: }
        !            36: 
        !            37: class TestClass {
        !            38:     public $pub;
        !            39:     static public $stat = "static property";
        !            40:     protected $prot = 4;
        !            41:     private $priv = "keepOut";
        !            42: }
        !            43: 
        !            44: reflectProperty("TestClass", "pub");
        !            45: reflectProperty("TestClass", "stat");
        !            46: reflectProperty("TestClass", "prot");
        !            47: reflectProperty("TestClass", "priv");
        !            48: 
        !            49: ?>
        !            50: --EXPECT--
        !            51: **********************************
        !            52: Reflecting on property TestClass::pub
        !            53: 
        !            54: __toString():
        !            55: string(35) "Property [ <default> public $pub ]
        !            56: "
        !            57: export():
        !            58: string(35) "Property [ <default> public $pub ]
        !            59: "
        !            60: export():
        !            61: Property [ <default> public $pub ]
        !            62: 
        !            63: NULL
        !            64: getName():
        !            65: string(3) "pub"
        !            66: isPublic():
        !            67: bool(true)
        !            68: isPrivate():
        !            69: bool(false)
        !            70: isProtected():
        !            71: bool(false)
        !            72: isStatic():
        !            73: bool(false)
        !            74: getValue():
        !            75: NULL
        !            76: getValue() after a setValue():
        !            77: string(8) "NewValue"
        !            78: 
        !            79: **********************************
        !            80: **********************************
        !            81: Reflecting on property TestClass::stat
        !            82: 
        !            83: __toString():
        !            84: string(33) "Property [ public static $stat ]
        !            85: "
        !            86: export():
        !            87: string(33) "Property [ public static $stat ]
        !            88: "
        !            89: export():
        !            90: Property [ public static $stat ]
        !            91: 
        !            92: NULL
        !            93: getName():
        !            94: string(4) "stat"
        !            95: isPublic():
        !            96: bool(true)
        !            97: isPrivate():
        !            98: bool(false)
        !            99: isProtected():
        !           100: bool(false)
        !           101: isStatic():
        !           102: bool(true)
        !           103: getValue():
        !           104: string(15) "static property"
        !           105: getValue() after a setValue():
        !           106: string(8) "NewValue"
        !           107: 
        !           108: **********************************
        !           109: **********************************
        !           110: Reflecting on property TestClass::prot
        !           111: 
        !           112: __toString():
        !           113: string(39) "Property [ <default> protected $prot ]
        !           114: "
        !           115: export():
        !           116: string(39) "Property [ <default> protected $prot ]
        !           117: "
        !           118: export():
        !           119: Property [ <default> protected $prot ]
        !           120: 
        !           121: NULL
        !           122: getName():
        !           123: string(4) "prot"
        !           124: isPublic():
        !           125: bool(false)
        !           126: isPrivate():
        !           127: bool(false)
        !           128: isProtected():
        !           129: bool(true)
        !           130: isStatic():
        !           131: bool(false)
        !           132: 
        !           133: **********************************
        !           134: **********************************
        !           135: Reflecting on property TestClass::priv
        !           136: 
        !           137: __toString():
        !           138: string(37) "Property [ <default> private $priv ]
        !           139: "
        !           140: export():
        !           141: string(37) "Property [ <default> private $priv ]
        !           142: "
        !           143: export():
        !           144: Property [ <default> private $priv ]
        !           145: 
        !           146: NULL
        !           147: getName():
        !           148: string(4) "priv"
        !           149: isPublic():
        !           150: bool(false)
        !           151: isPrivate():
        !           152: bool(true)
        !           153: isProtected():
        !           154: bool(false)
        !           155: isStatic():
        !           156: bool(false)
        !           157: 
        !           158: **********************************
        !           159: 
        !           160: 

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