Annotation of embedaddon/php/Zend/tests/bug32322.phpt, revision 1.1

1.1     ! misho       1: --TEST--
        !             2: Bug #32322 (Return values by reference broken( using self::),example singleton instance)
        !             3: --INI--
        !             4: error_reporting=4095
        !             5: --FILE--
        !             6: <?php
        !             7: class test
        !             8: {
        !             9:     private static $instance = null;
        !            10:     private $myname = '';
        !            11:     
        !            12:     private function __construct( $value = '' ) 
        !            13:     {
        !            14:         echo "New class $value created \n";
        !            15:         $this -> myname = $value;
        !            16:     }
        !            17:     private function __clone() {}
        !            18:     static public function getInstance()
        !            19:     {
        !            20:         if ( self::$instance == null )
        !            21:         {
        !            22:             self::$instance = new test('Singleton1');
        !            23:         }
        !            24:         else {
        !            25:             echo "Using old class " . self::$instance -> myname . "\n";
        !            26:         }
        !            27:         return self::$instance;
        !            28:     }
        !            29:     static public function getInstance2()
        !            30:     {
        !            31:         static $instance2 = null;
        !            32:         if ( $instance2 == null )
        !            33:         {
        !            34:             $instance2 = new test('Singleton2');
        !            35:         }
        !            36:         else {
        !            37:             echo "Using old class " . $instance2 -> myname . "\n";
        !            38:         }
        !            39:         return $instance2;
        !            40:     }
        !            41:     public function __destruct() 
        !            42:     {
        !            43:         if ( defined('SCRIPT_END') )
        !            44:         {
        !            45:             echo "Class " . $this -> myname . " destroyed at script end\n";
        !            46:         } else {
        !            47:             echo "Class " . $this -> myname . " destroyed beforce script end\n";
        !            48:         }
        !            49:     }
        !            50: }    
        !            51: echo "Try static instance inside class :\n";
        !            52: $getCopyofSingleton    = test::getInstance();
        !            53: $getCopyofSingleton    = null;
        !            54: $getCopyofSingleton    = &test::getInstance();
        !            55: $getCopyofSingleton    = null;
        !            56: $getCopyofSingleton    = test::getInstance();
        !            57: echo "Try static instance inside function :\n";
        !            58: $getCopyofSingleton2   = test::getInstance2();
        !            59: $getCopyofSingleton2   = null;
        !            60: $getCopyofSingleton2   = &test::getInstance2();
        !            61: $getCopyofSingleton2   = null;
        !            62: $getCopyofSingleton2   = test::getInstance2();
        !            63: 
        !            64: define('SCRIPT_END',1);
        !            65: ?>
        !            66: --EXPECTF--
        !            67: Try static instance inside class :
        !            68: New class Singleton1 created 
        !            69: Using old class Singleton1
        !            70: 
        !            71: Strict Standards: Only variables should be assigned by reference in %sbug32322.php on line 49
        !            72: Using old class Singleton1
        !            73: Try static instance inside function :
        !            74: New class Singleton2 created 
        !            75: Using old class Singleton2
        !            76: 
        !            77: Strict Standards: Only variables should be assigned by reference in %sbug32322.php on line 55
        !            78: Using old class Singleton2
        !            79: Class Singleton1 destroyed at script end
        !            80: Class Singleton2 destroyed at script end

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