Hi, not a bug in php a bug in my brain.
returning references from functions only works if you have & on function-declaration and call: $db1 = &itk_new_db(); $db1->connect(); $db2 = &itk_new_db(); and then it works, bye, Michael Bretterklieber schrieb: > Hi, > > I found a bug in php4.2.1 (Windows XP, IIS with php as CGI). > > - I have a db-class wich stores the resource-id of a db-connection. > - I have a function (itk_new_db) where I return an object of the class > above and I remember this object in a static-var. > - the second call on that function (itk_new_db) returns the same object, > but the resource-id is lost????!?!?!? > > This nice feature also exists with com-objects. This seems to be a cool > bug in the resource-manager of php. > > Any hints? If not I make a bugreport. > > class db_class { > var $dbc = null; > > function connect() { > $this->dbc = mssql_connect('wincubix', 'oebb', 'oebb'); > // $this->dbc = mysql_connect('localhost:3308', 'root', '') > } > } > > function &itk_new_db(){ > static $db; > > if (!isset($db)) $db = new db_class; > > return $db; > } > > $db1 = itk_new_db(); > $db1->connect(); > $db2 = itk_new_db(); > > if ($db1 === $db2) echo 'ident<br>'; > > echo 'S1'.$db1->dbc.'<br>' ; > echo 'S2'.$db2->dbc.'<br>' ; > > > bye, -- -------------------------------------- Michael Bretterklieber LCP JAWA Management Software GmbH Liebenauer Hauptstr. 200 A-8041 GRAZ Tel: ++43-(0)316-403274-12 Fax: ++43-(0)316-403274-10 GSM: ++43-(0)676-93 96 698 [EMAIL PROTECTED] homepage: http://www.jawa.at --------- privat ----------- E-mail: [EMAIL PROTECTED] homepage: http://www.inode.at/mbretter -------------------------------------- "...the number of UNIX installations has grown to 10, with more expected..." - Dennis Ritchie and Ken Thompson, June 1972 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php