From:             martin at ibuildings dot nl
Operating system: Redhat 6.1
PHP version:      4.3.4
PHP Bug Type:     Scripting Engine problem
Bug description:  Compilation error in libmysql.c

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 bug report at http://bugs.php.net/?id=27219&edit=1
-- 
Try a CVS snapshot (php4):  http://bugs.php.net/fix.php?id=27219&r=trysnapshot4
Try a CVS snapshot (php5):  http://bugs.php.net/fix.php?id=27219&r=trysnapshot5
Fixed in CVS:               http://bugs.php.net/fix.php?id=27219&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=27219&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=27219&r=needtrace
Need Reproduce Script:      http://bugs.php.net/fix.php?id=27219&r=needscript
Try newer version:          http://bugs.php.net/fix.php?id=27219&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=27219&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=27219&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=27219&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=27219&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=27219&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=27219&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=27219&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=27219&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=27219&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=27219&r=float

Reply via email to