UNSUBSCRIBE ME PLEASE!!!!!!!!!!!!!!

[EMAIL PROTECTED] schrieb:

From:             [EMAIL PROTECTED]
Operating system: Linux
PHP version:      4.0.6
PHP Bug Type:     Variables related
Bug description:  Static references are transient inside methods

Another unfortunate bug with references appears to be that statics holding
references inside methods are actually transient, and a reference will be
lost.

For example, calling the following code several times will initialise $db
and return every time with a new instance.

function &getInstance()
  {
    static $db;

    if (!isset($db)) {
      $db =& new FS_DB();
    }

    return $db;
  }

whereas the following will give true singeton behaviour and initialise just
once, as expected.

function &getInstance()
  {
    static $db;

    if (!isset($db)) {
      $db = new FS_DB();
    }

    return $db;
  }

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

--
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to