ID:               27219
 User updated by:  ivo at ibuildings dot nl
-Summary:          Compilation error in libmysql.c
-Reported By:      martin at ibuildings dot nl
+Reported By:      ivo at ibuildings dot nl
 Status:           Open
 Bug Type:         Scripting Engine problem
-Operating System: Redhat 6.1
+Operating System: Gentoo, Redhat 9
 PHP Version:      4.3.4
 New Comment:

Sorry, browser autocomplete filled in wrong defaults.


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

[2004-02-11 08:49:20] ivo at ibuildings dot nl

Description:
------------
When a class does not have member variables, creating a static instance
of the class becomes impossible. See the code below. If the member
variable is declared, one onstance is created, and each next call to
getInstance will return the existing instance.Without the member var,
new instances are created every time.

Reproduce code:
---------------
class mySingleton
{
  // var $m_dummy = ""; // uncommenting this line is a 
                        // workaround

  function &getInstance()
  {
    static $s_instance = NULL;
    if ($s_instance == NULL)
    {
      echo "Creating a new instance<br>";
      $s_instance = new mySingleton();
    }
    else
    {
      echo "Using existing instance<br>";
    }
    return $s_instance;
  }
}

$tmp = &mySingleton::getIntance();
$tmp2 = &mySingleton::getIntance();



Expected result:
----------------
Creating a new instance
Using existing instance

Actual result:
--------------
Creating a new instance
Creating a new instance


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


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

Reply via email to