ID:               32322
 User updated by:  rickd at commando-pernod dot net
 Reported By:      rickd at commando-pernod dot net
-Status:           Feedback
+Status:           Open
 Bug Type:         Zend Engine 2 problem
 Operating System: Win2000
 PHP Version:      5.0.3
 New Comment:

CVS snapshot the same, getInstance() returning reference none copy of
var, only way at the moment is this little workaround ( when using
private static in class not in function ):


    public static function getInstance()
    {
        if ( self::$instance == null )
        {
            self::$instance = new test();
        }
        else {
            echo "old";
        }
        return ( $r =& self::$instance);
    }


Previous Comments:
------------------------------------------------------------------------

[2005-03-18 19:26:19] [EMAIL PROTECTED]

Please try using this CVS snapshot:

  http://snaps.php.net/php5-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5-win32-latest.zip



------------------------------------------------------------------------

[2005-03-15 21:03:10] rickd at commando-pernod dot net

same but static inside class function and cant be killed with
referencing, remember in the other code i dont use &getinstance() so
the function do not return a reference how its describe in manual (
both need reference, caller and function code)

class test {
   static function getinstance() {
      static $instance;
      if ( $instance == null ) {
         $instance = new test();
      }
      return $instance;
   }
}
$user = &test::getinstance();
$user = null; // dont destroy instance
$user = &test::getinstance();
unset( $user ); // dont destroy instance

------------------------------------------------------------------------

[2005-03-15 21:00:00] rickd at commando-pernod dot net

upps i did i typing mistake :

so i mean

class test {
   static private $instance = null;
   static function getinstance() {
      if ( self::$instance == null ) {
         self::$instance = new test();
      }
      return self::$instance;
   }
}
$user = &test::getinstance();
$user = null; // destroy singleton instance
$user = &test::getinstance();
unset( $user ); // dont destroy instance

------------------------------------------------------------------------

[2005-03-15 20:29:41] [EMAIL PROTECTED]

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Please use support forums to get help with your singleton 
implementation... 

------------------------------------------------------------------------

[2005-03-15 19:54:01] rickd at commando-pernod dot net

Description:
------------
We use a user singleton instance for our cms user authed ids that
should not be able to killed from third party addons or worse coders so
easily, but accessable from all.

But when someone get the instance with reference it can be killed easy
with setting the reference var to null, unset dont work.

If you put the static $instance holder inside the getinstance()
function it seems to be work correct and cant be deleted from setting
reference to NULL



Reproduce code:
---------------
class test {
   static private $instance = null;
   static function getinstance() {
      if ( self::$instance == null ) {
         return new test();
      }
      return self::$instance;
   }
}
$user = &test::getinstance();
$user = null; // destroy singleton instance
$user = &test::getinstance();
unset( $user ); // dont destroy instance

Expected result:
----------------
singleton not destroying with setting a getted instance with
reference to null

Actual result:
--------------
singleton destroyed


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=32322&edit=1

Reply via email to