Annotation of embedaddon/php/tests/classes/factory_and_singleton_002.phpt, revision 1.1

1.1     ! misho       1: --TEST--
        !             2: ZE2 factory and singleton, test 2
        !             3: --SKIPIF--
        !             4: <?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 needed'); ?>
        !             5: --FILE--
        !             6: <?php
        !             7: class test {
        !             8:   protected $x;
        !             9: 
        !            10:   static private $test = NULL;
        !            11:   static private $cnt = 0;
        !            12: 
        !            13:   static function factory($x) {
        !            14:     if (test::$test) {
        !            15:       return test::$test;
        !            16:     } else {
        !            17:       test::$test = new test($x);
        !            18:       return test::$test;
        !            19:     }
        !            20:   }
        !            21: 
        !            22:   protected function __construct($x) {
        !            23:     test::$cnt++;
        !            24:     $this->x = $x;
        !            25:   }
        !            26: 
        !            27:   static function destroy() {
        !            28:     test::$test = NULL;
        !            29:   }
        !            30: 
        !            31:   protected function __destruct() {
        !            32:        test::$cnt--;
        !            33:   }
        !            34: 
        !            35:   public function get() {
        !            36:     return $this->x;
        !            37:   }
        !            38: 
        !            39:   static public function getX() {
        !            40:     if (test::$test) {
        !            41:       return test::$test->x;
        !            42:     } else {
        !            43:       return NULL;
        !            44:     }
        !            45:   }
        !            46:   
        !            47:   static public function count() {
        !            48:     return test::$cnt;
        !            49:   }
        !            50: }
        !            51: 
        !            52: echo "Access static members\n";
        !            53: var_dump(test::getX());
        !            54: var_dump(test::count());
        !            55: 
        !            56: echo "Create x and y\n";
        !            57: $x = test::factory(1);
        !            58: $y = test::factory(2);
        !            59: var_dump(test::getX());
        !            60: var_dump(test::count());
        !            61: var_dump($x->get());
        !            62: var_dump($y->get());
        !            63: 
        !            64: echo "Destruct x\n";
        !            65: $x = NULL;
        !            66: var_dump(test::getX());
        !            67: var_dump(test::count());
        !            68: var_dump($y->get());
        !            69: 
        !            70: echo "Destruct y\n";
        !            71: $y = NULL;
        !            72: var_dump(test::getX());
        !            73: var_dump(test::count());
        !            74: 
        !            75: //echo "Destruct static\n";
        !            76: //test::destroy();
        !            77: //var_dump(test::getX());
        !            78: //var_dump(test::count());
        !            79: 
        !            80: echo "Done\n";
        !            81: ?>
        !            82: --EXPECT--
        !            83: Access static members
        !            84: NULL
        !            85: int(0)
        !            86: Create x and y
        !            87: int(1)
        !            88: int(1)
        !            89: int(1)
        !            90: int(1)
        !            91: Destruct x
        !            92: int(1)
        !            93: int(1)
        !            94: int(1)
        !            95: Destruct y
        !            96: int(1)
        !            97: int(1)
        !            98: Done
        !            99: 
        !           100: Warning: Call to protected test::__destruct() from context '' during shutdown ignored in Unknown on line 0

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