From: Jens dot Pilgrim at xx-well dot com
Operating system: Windows 2000
PHP version: 4.3.0
PHP Bug Type: Reproducible crash
Bug description: ] Problem with "=& new" and locally created instances
Hi,
I've got a problem with the "=& new" construct. A code sample tells more
than 1000 words:
<?php
class foo {}
$g_fooInstance = null;
class factory {
function factory() {
global $g_fooInstance;
if (is_null($g_fooInstance)) {
$g_fooInstance =& new foo(); // <-- here's the problem
// $g_fooInstance = new foo(); // <-- this works
}
}
}
function main() {
$theFactory =& new factory();
global $g_fooInstance;
if (is_null($g_fooInstance)) {
echo ('This isn\'t expected - why is it null?');
} else {
echo ('It works as expected');
}
}
// run
main();
?>
This code is running like that and demonstrates exactly the "weird"
behaviour.
Running this example, the variable $g_fooInstance is null in function
main(). But why? Is the reference to the constructed object descructed
after leaving the scope of function factory::factory()? Or in other words,
are locally created instances always destructed, regardless if there are
other references on the instance?
I've posted this bug as a question in the general mailing list (on Fr
03/28/2003), and others tested and reproduced this bug too...
Regards,
jens
--
Edit bug report at http://bugs.php.net/?id=22981&edit=1
--
Try a CVS snapshot: http://bugs.php.net/fix.php?id=22981&r=trysnapshot
Fixed in CVS: http://bugs.php.net/fix.php?id=22981&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=22981&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=22981&r=needtrace
Try newer version: http://bugs.php.net/fix.php?id=22981&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=22981&r=support
Expected behavior: http://bugs.php.net/fix.php?id=22981&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=22981&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=22981&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=22981&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=22981&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=22981&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=22981&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=22981&r=gnused