[Tickets #6837] Singletons and references

bugs at horde.org bugs at horde.org
Wed Jun 4 19:10:00 UTC 2008


DO NOT REPLY TO THIS MESSAGE. THIS EMAIL ADDRESS IS NOT MONITORED.

Ticket URL: http://bugs.horde.org/ticket/6837
-----------------------------------------------------------------------
 Ticket             | 6837
 Created By         | thomas.jarosch at intra2net.com
 Summary            | Singletons and references
 Queue              | Horde Framework Packages
 Version            | HEAD
 Type               | Bug
 State              | Unconfirmed
 Priority           | 1. Low
 Milestone          |
 Patch              |
 Owners             |
-----------------------------------------------------------------------


thomas.jarosch at intra2net.com (2008-06-04 15:09) wrote:

Hello together,

I'm currently debugging a heap memory corruption in PHP (5.2.6) using
Horde
and noticed some odd behavior regarding references and static variables.
Currently we implement some of our singletons like this:

-----------------------------
function &singleton()
{
    static $history;

    if (!isset($history)) {
        $history = &new Horde_History();
    }

    return $history;
}
-----------------------------

I've found out that the singleton is not working and it's related to
this:
http://www.php.net/manual/en/language.variables.scope.php
The part with "References with global and static variables" is important.

-> The code has to be changed to "$history = new Horde_History();"
Singletons storing their references via an array are unaffected.

If there a no objections I'll start fixing the static variables.

I really hope this will solve my trouble (=segfaults) deep inside
the PHP memory manager during request shutdown. Spending two days
in gdb, debugging internal PHP memory structures is no fun at all :o)

Cheers,
Thomas





More information about the bugs mailing list