File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / Zend / tests / bug32322.phpt
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Tue Feb 21 23:47:52 2012 UTC (13 years, 1 month ago) by misho
Branches: php, MAIN
CVS tags: v5_4_3elwix, v5_4_29p0, v5_4_29, v5_4_20p0, v5_4_20, v5_4_17p0, v5_4_17, v5_3_10, HEAD
php

    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>