<?xml version="1.0" encoding="UTF-8"?> 
<?xml-stylesheet href="https://dev.horde.org/themes/horde//default/feed-rss.xsl" type="text/xsl"?> 
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> 
 <channel> 
  <title>Singletons and references</title> 
  <pubDate>Fri, 10 Apr 2026 17:02:40 +0000</pubDate> 
  <link>https://bugs.horde.org/ticket/6837</link> 
  <atom:link rel="self" type="application/rss+xml" title="Singletons and references" href="https://bugs.horde.org/ticket/6837/rss" /> 
  <description>Singletons and references</description> 
 
   
   
  <item> 
   <title>Hello together,



I&#039;m currently debugging a heap memory cor</title> 
   <description>Hello together,



I&#039;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 &amp;singleton()

{

    static $history;



    if (!isset($history)) {

        $history = &amp;new Horde_History();

    }



    return $history;

}

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



I&#039;ve found out that the singleton is not working and it&#039;s related to this:

http://www.php.net/manual/en/language.variables.scope.php

The part with &quot;References with global and static variables&quot; is important.



-&gt; The code has to be changed to &quot;$history = new Horde_History();&quot;

Singletons storing their references via an array are unaffected.



If there a no objections I&#039;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

</description> 
   <pubDate>Wed, 04 Jun 2008 19:09:59 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/6837#t45928</link> 
  </item> 
   
  <item> 
   <title>That is correct - we should never assign a reference to a st</title> 
   <description>That is correct - we should never assign a reference to a static variable. Anywhere this crept in is an error.</description> 
   <pubDate>Wed, 04 Jun 2008 19:15:55 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/6837#t45929</link> 
  </item> 
   
  <item> 
   <title>Taking the liberty of assigning to Thomas - thanks for looki</title> 
   <description>Taking the liberty of assigning to Thomas - thanks for looking in to this!</description> 
   <pubDate>Wed, 04 Jun 2008 21:32:30 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/6837#t45931</link> 
  </item> 
   
  <item> 
   <title>Actually, I don&#039;t think this has anything to do with what yo</title> 
   <description>Actually, I don&#039;t think this has anything to do with what you see, because the PHP manual  explicitly refers to Zend Engine 1.

Beside that, what Chuck said.</description> 
   <pubDate>Wed, 04 Jun 2008 21:41:24 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/6837#t45936</link> 
  </item> 
   
  <item> 
   <title>&gt; Actually, I don&#039;t think this has anything to do with what </title> 
   <description>&gt; Actually, I don&#039;t think this has anything to do with what you see, 

&gt; because the PHP manual  explicitly refers to Zend Engine 1.



Everything seems to run smooth until one of those classes created by our &quot;wrong&quot; singleton contains an object like PEAR_Error. My Horde_History object does this as I don&#039;t use a SQL backend. PEAR_Error contains cyclic references internally.



PHP 5.2.x currently doesn&#039;t handle cleanup of cyclic references. PHP 5.3.x should be fixed, but it doesn&#039;t work properly. I filed an upstream bug: http://bugs.php.net/?id=45178



My feeling tells me that something with all those (cyclic) references goes wrong during cleanup/reference counting/whatever. Let&#039;s see what happens after I have fixed the singletons.

</description> 
   <pubDate>Thu, 05 Jun 2008 08:07:31 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/6837#t45977</link> 
  </item> 
   
  <item> 
   <title>&gt; PHP 5.2.x currently doesn&#039;t handle cleanup of cyclic refer</title> 
   <description>&gt; PHP 5.2.x currently doesn&#039;t handle cleanup of cyclic references. PHP 

&gt; 5.3.x should be fixed, but it doesn&#039;t work properly. I filed an 

&gt; upstream bug: http://bugs.php.net/?id=45178



Your upstream bug contains an incorrect statement:

The supplied code is the standard way Horde does it singletons. We always used the syntax of &quot;$object = &amp;new class&quot; to make it work  with PHP4 and PHP5. 



As Chuck mentioned, the code you provided in that bug report is most definitely *not* the &quot;standard&quot; syntax we use.  If that syntax does appear anywhere, it is an error and needs to be fixed (thus this bug report).  Regardless of whether PHP is leaking memory or not, this needs to be cleaned up regardless if just because semantically it is incorrect.</description> 
   <pubDate>Thu, 05 Jun 2008 08:24:42 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/6837#t45979</link> 
  </item> 
   
  <item> 
   <title>&gt; Your upstream bug contains an incorrect statement:

&gt; The </title> 
   <description>&gt; Your upstream bug contains an incorrect statement:

&gt; The supplied code is the standard way Horde does it singletons. We 

&gt; always used the syntax of &quot;$object = &amp;new class&quot; to make it work  

&gt; with PHP4 and PHP5.



Yeah I know, sorry, I wrote that comment before I learned more information as I just checked Horde_History, Group and Perms. It was not easy to find the actual problem as it&#039;s close to #5355, but not 100% related.

</description> 
   <pubDate>Thu, 05 Jun 2008 08:38:33 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/6837#t45980</link> 
  </item> 
   
  <item> 
   <title>&gt; PHP 5.2.x currently doesn&#039;t handle cleanup of cyclic refer</title> 
   <description>&gt; PHP 5.2.x currently doesn&#039;t handle cleanup of cyclic references. PHP 

&gt; 5.3.x should be fixed, but it doesn&#039;t work properly. 



circular references patch will not be implemented in PHP 5.3 because it did not have many votes.. See: http://news.php.net/php.internals/32330. You should clean up references by your own with a destroy function.  Adding this code into the &quot;magic&quot; __destruct() method is impossible because is called when an object can be destroyed  as is still referenced it means never.</description> 
   <pubDate>Thu, 05 Jun 2008 09:00:14 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/6837#t45982</link> 
  </item> 
   
  <item> 
   <title>&gt; circular references patch will not be implemented in PHP 5</title> 
   <description>&gt; circular references patch will not be implemented in PHP 5.3 because it did not have many votes.. See: http://news.php.net/php.internals/32330. 



http://bugs.php.net/bug.php?id=33595 states it&#039;s fixed in PHP5_3. Hmm.

</description> 
   <pubDate>Thu, 05 Jun 2008 09:05:48 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/6837#t45985</link> 
  </item> 
   
  <item> 
   <title>&gt; Your upstream bug contains an incorrect statement:



Fixe</title> 
   <description>&gt; Your upstream bug contains an incorrect statement:



Fixed upstream ;-)

</description> 
   <pubDate>Thu, 05 Jun 2008 09:37:23 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/6837#t45989</link> 
  </item> 
   
  <item> 
   <title>Yipeeee, my segfaults are gone :-)



I&#039;ve splitted the modi</title> 
   <description>Yipeeee, my segfaults are gone :-)



I&#039;ve splitted the modifications into patches that really fix things and patches that are simplifying the singleton code.



Let&#039;s start with the patch for &quot;horde&quot;.

</description> 
   <pubDate>Thu, 05 Jun 2008 16:10:47 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/6837#t45999</link> 
  </item> 
   
  <item> 
   <title>Fix singleton in Turba and also intitialize three variables </title> 
   <description>Fix singleton in Turba and also intitialize three variables properly.



</description> 
   <pubDate>Thu, 05 Jun 2008 16:12:03 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/6837#t46000</link> 
  </item> 
   
  <item> 
   <title>Simplify patch for nag.

</title> 
   <description>Simplify patch for nag.

</description> 
   <pubDate>Thu, 05 Jun 2008 16:12:48 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/6837#t46001</link> 
  </item> 
   
  <item> 
   <title>Simplify patch for mnemo.

</title> 
   <description>Simplify patch for mnemo.

</description> 
   <pubDate>Thu, 05 Jun 2008 16:13:14 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/6837#t46002</link> 
  </item> 
   
  <item> 
   <title>Simplify patch for kronolith.</title> 
   <description>Simplify patch for kronolith.</description> 
   <pubDate>Thu, 05 Jun 2008 16:13:42 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/6837#t46004</link> 
  </item> 
   
  <item> 
   <title>Simplify patch for imp.

</title> 
   <description>Simplify patch for imp.

</description> 
   <pubDate>Thu, 05 Jun 2008 16:14:10 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/6837#t46005</link> 
  </item> 
   
  <item> 
   <title>Simplify patch for framework</title> 
   <description>Simplify patch for framework</description> 
   <pubDate>Thu, 05 Jun 2008 16:15:00 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/6837#t46006</link> 
  </item> 
   
  <item> 
   <title>Most important patch: Fix singletons in framework.



Please</title> 
   <description>Most important patch: Fix singletons in framework.



Please check the changes in Group/Group.php and Kolab/IMAP.php.

Those were the most &quot;complex&quot; ones.



Enjoy :-)

</description> 
   <pubDate>Thu, 05 Jun 2008 16:17:17 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/6837#t46007</link> 
  </item> 
   
  <item> 
   <title>Changes have been made in CVS for this ticket:

  http://cvs</title> 
   <description>Changes have been made in CVS for this ticket:

  http://cvs.horde.org/diff.php/framework/Browser/Browser.php?r1=1.238&amp;r2=1.239&amp;ty=u
  http://cvs.horde.org/diff.php/framework/Crypt/Crypt.php?r1=1.48&amp;r2=1.49&amp;ty=u
  http://cvs.horde.org/diff.php/framework/Data/Data.php?r1=1.99&amp;r2=1.100&amp;ty=u
  http://cvs.horde.org/diff.php/framework/DataTree/DataTree.php?r1=1.187&amp;r2=1.188&amp;ty=u
  http://cvs.horde.org/diff.php/framework/Editor/Editor.php?r1=1.24&amp;r2=1.25&amp;ty=u
  http://cvs.horde.org/diff.php/framework/Form/Form/Action.php?r1=1.29&amp;r2=1.30&amp;ty=u
  http://cvs.horde.org/diff.php/framework/Form/Form/Renderer.php?r1=1.220&amp;r2=1.221&amp;ty=u
  http://cvs.horde.org/diff.php/framework/IMAP/IMAP/ACL.php?r1=1.17&amp;r2=1.18&amp;ty=u
  http://cvs.horde.org/diff.php/framework/Image/Image.php?r1=1.67&amp;r2=1.68&amp;ty=u
  http://cvs.horde.org/diff.php/framework/NLS/NLS.php?r1=1.121&amp;r2=1.122&amp;ty=u
  http://cvs.horde.org/diff.php/framework/Net_IMSP/IMSP.php?r1=1.39&amp;r2=1.40&amp;ty=u
  http://cvs.horde.org/diff.php/framework/Prefs/Identity.php?r1=1.12&amp;r2=1.13&amp;ty=u
  http://cvs.horde.org/diff.php/framework/Token/Token.php?r1=1.50&amp;r2=1.51&amp;ty=u
  http://cvs.horde.org/diff.php/framework/VFS/lib/VFS.php?r1=1.6&amp;r2=1.7&amp;ty=u</description> 
   <pubDate>Fri, 06 Jun 2008 04:15:50 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/6837#t46013</link> 
  </item> 
   
  <item> 
   <title>Changes have been made in CVS for this ticket:

  http://cvs</title> 
   <description>Changes have been made in CVS for this ticket:

  http://cvs.horde.org/diff.php/horde/po/translation.php?r1=1.124&amp;r2=1.125&amp;ty=u
  http://cvs.horde.org/diff.php/imp/lib/IMAP/ACL.php?r1=1.5&amp;r2=1.6&amp;ty=u
  http://cvs.horde.org/diff.php/imp/lib/Quota.php?r1=1.35&amp;r2=1.36&amp;ty=u
  http://cvs.horde.org/diff.php/kronolith/lib/FBView.php?r1=1.28&amp;r2=1.29&amp;ty=u
  http://cvs.horde.org/diff.php/kronolith/lib/Storage.php?r1=1.7&amp;r2=1.8&amp;ty=u
  http://cvs.horde.org/diff.php/mnemo/lib/Driver.php?r1=1.41&amp;r2=1.42&amp;ty=u
  http://cvs.horde.org/diff.php/nag/lib/Driver.php?r1=1.116&amp;r2=1.117&amp;ty=u
  http://cvs.horde.org/diff.php/turba/lib/Driver/ldap.php?r1=1.89&amp;r2=1.90&amp;ty=u
  http://cvs.horde.org/diff.php/turba/lib/Driver/sql.php?r1=1.113&amp;r2=1.114&amp;ty=u
  http://cvs.horde.org/diff.php/turba/lib/Maintenance/Task/upgradelists.php?r1=1.7&amp;r2=1.8&amp;ty=u
  http://cvs.horde.org/diff.php/turba/lib/Maintenance/Task/upgradeprefs.php?r1=1.11&amp;r2=1.12&amp;ty=u</description> 
   <pubDate>Fri, 06 Jun 2008 04:25:14 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/6837#t46015</link> 
  </item> 
   
  <item> 
   <title>This last patch is a bit confusing, since some places you&#039;re</title> 
   <description>This last patch is a bit confusing, since some places you&#039;re adding references too. Also, please be very very careful with that change to Horde::getLogger - we&#039;ve had problems before when the shutdown function of PEAR_Log doesn&#039;t run, and nothing gets logged.</description> 
   <pubDate>Fri, 06 Jun 2008 04:36:00 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/6837#t46025</link> 
  </item> 
   
  <item> 
   <title>&gt; This last patch is a bit confusing, since some places you&#039;</title> 
   <description>&gt; This last patch is a bit confusing, since some places you&#039;re adding 

&gt; references too.



Yes, this fixes the factory/singleton code for PHP4. You can drop that part if you want as I switched to PHP5 and PHP4 is out of maintenance (-&gt;doomed) anyway.

I only added it in places where the factory and singleton code is already defined as &quot;function &amp;factory()&quot; and &quot;function &amp;singleton()&quot;, so it should make no difference. I&#039;m really happy they changed the default &quot;copy&quot; behavior in PHP5 :-)



Regarding the logger change: The $logger variable is defined as a normal &quot;static&quot; var, so the code looked wrong to me. Do you have a test case where it failed in the past? Normal logging f.e. of IMAP logins still works for me with the new code.

</description> 
   <pubDate>Fri, 06 Jun 2008 09:21:23 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/6837#t46044</link> 
  </item> 
   
  <item> 
   <title>Changes have been made in CVS for this ticket:

http://cvs.h</title> 
   <description>Changes have been made in CVS for this ticket:

http://cvs.horde.org/diff.php/framework/Form/Form.php?r1=1.431&amp;r2=1.432&amp;ty=u
http://cvs.horde.org/diff.php/framework/Group/Group.php?r1=1.112&amp;r2=1.113&amp;ty=u
http://cvs.horde.org/diff.php/framework/History/History.php?r1=1.60&amp;r2=1.61&amp;ty=u
http://cvs.horde.org/diff.php/framework/Horde/Horde.php?r1=1.679&amp;r2=1.680&amp;ty=u
http://cvs.horde.org/diff.php/framework/Kolab/Kolab/IMAP.php?r1=1.23&amp;r2=1.24&amp;ty=u
http://cvs.horde.org/diff.php/framework/Kolab/Kolab/LDAP.php?r1=1.8&amp;r2=1.9&amp;ty=u
http://cvs.horde.org/diff.php/framework/Notification/Notification.php?r1=1.67&amp;r2=1.68&amp;ty=u
http://cvs.horde.org/diff.php/framework/Perms/Perms.php?r1=1.102&amp;r2=1.103&amp;ty=u
http://cvs.horde.org/diff.php/framework/UI/UI/VarRenderer/html.php?r1=1.174&amp;r2=1.175&amp;ty=u
http://cvs.horde.org/diff.php/framework/VC/VC.php?r1=1.26&amp;r2=1.27&amp;ty=u</description> 
   <pubDate>Sat, 07 Jun 2008 16:00:09 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/6837#t46082</link> 
  </item> 
   
  <item> 
   <title>Looks like it worked when Log::singleton was assigned to a s</title> 
   <description>Looks like it worked when Log::singleton was assigned to a static before, and only broke when we removed the static and didn&#039;t add the &amp;.</description> 
   <pubDate>Sat, 07 Jun 2008 16:00:29 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/6837#t46083</link> 
  </item> 
   
   
 
 </channel> 
</rss> 
