<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: PHP: Creating a singleton class for serialization</title>
	<atom:link href="http://www.sematopia.com/2007/09/php-creating-a-singleton-class-for-serialization/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sematopia.com/2007/09/php-creating-a-singleton-class-for-serialization/</link>
	<description></description>
	<lastBuildDate>Sun, 05 Sep 2010 04:49:46 -0400</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: mojo</title>
		<link>http://www.sematopia.com/2007/09/php-creating-a-singleton-class-for-serialization/comment-page-1/#comment-107091</link>
		<dc:creator>mojo</dc:creator>
		<pubDate>Wed, 16 Jul 2008 17:10:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.sematopia.com/?p=216#comment-107091</guid>
		<description>For me that works fine. Even if it might not 100% be the idea of a singleton pattern</description>
		<content:encoded><![CDATA[<p>For me that works fine. Even if it might not 100% be the idea of a singleton pattern</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mojo</title>
		<link>http://www.sematopia.com/2007/09/php-creating-a-singleton-class-for-serialization/comment-page-1/#comment-107084</link>
		<dc:creator>mojo</dc:creator>
		<pubDate>Wed, 16 Jul 2008 16:42:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.sematopia.com/?p=216#comment-107084</guid>
		<description>try this:
	public function __wakeup()
	{
		if( isset($this-&gt;me) ) self::$instance = $this-&gt;me;
	}
	
	public function __sleep()
	{
		$this-&gt;me 	= self::$instance;
		
		return array_keys(get_object_vars($this));
	}</description>
		<content:encoded><![CDATA[<p>try this:<br />
	public function __wakeup()<br />
	{<br />
		if( isset($this-&gt;me) ) self::$instance = $this-&gt;me;<br />
	}</p>
<p>	public function __sleep()<br />
	{<br />
		$this-&gt;me 	= self::$instance;</p>
<p>		return array_keys(get_object_vars($this));<br />
	}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: beginner</title>
		<link>http://www.sematopia.com/2007/09/php-creating-a-singleton-class-for-serialization/comment-page-1/#comment-66075</link>
		<dc:creator>beginner</dc:creator>
		<pubDate>Tue, 26 Feb 2008 10:02:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.sematopia.com/?p=216#comment-66075</guid>
		<description>@ploceus: Well... I guess, now I can imagine what might have caused a trouble for you.

In PHP 5.1.6 you cannot call register_shutdown_function from a static class method. Instead, you have to pass an array of the class name and the function name. An explanation and examples are found &lt;a href=&quot;http://fi.php.net/register_shutdown_function#77074&quot; title=&quot;How to register a static method as a shutdown function&quot; rel=&quot;nofollow&quot;&gt;here&lt;/a&gt;. They say this works in PHP 4 too!

As of PHP 5.2.3 one can simply pass &#039;ClassName::methodName&#039;, and it would work.</description>
		<content:encoded><![CDATA[<p>@ploceus: Well&#8230; I guess, now I can imagine what might have caused a trouble for you.</p>
<p>In PHP 5.1.6 you cannot call register_shutdown_function from a static class method. Instead, you have to pass an array of the class name and the function name. An explanation and examples are found <a href="http://fi.php.net/register_shutdown_function#77074" title="How to register a static method as a shutdown function" rel="nofollow">here</a>. They say this works in PHP 4 too!</p>
<p>As of PHP 5.2.3 one can simply pass &#8216;ClassName::methodName&#8217;, and it would work.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: beginner</title>
		<link>http://www.sematopia.com/2007/09/php-creating-a-singleton-class-for-serialization/comment-page-1/#comment-66032</link>
		<dc:creator>beginner</dc:creator>
		<pubDate>Tue, 26 Feb 2008 08:31:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.sematopia.com/?p=216#comment-66032</guid>
		<description>Thanks, you saved me a lot of time! Your example works smoothly for me.

@ploceus: Static variables are not saved on serialization and, thus, not loaded on unserialization. However, one could try to mimic the feature by storing them manually in the object with __sleep() function and restoring in the __wakeup() function or, if that doesn&#039;t work, in the setInstance(). Personally, the only static variable I have is the reference to an instance of my class, and everything works as it should.</description>
		<content:encoded><![CDATA[<p>Thanks, you saved me a lot of time! Your example works smoothly for me.</p>
<p>@ploceus: Static variables are not saved on serialization and, thus, not loaded on unserialization. However, one could try to mimic the feature by storing them manually in the object with __sleep() function and restoring in the __wakeup() function or, if that doesn&#8217;t work, in the setInstance(). Personally, the only static variable I have is the reference to an instance of my class, and everything works as it should.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ploceus</title>
		<link>http://www.sematopia.com/2007/09/php-creating-a-singleton-class-for-serialization/comment-page-1/#comment-43916</link>
		<dc:creator>ploceus</dc:creator>
		<pubDate>Fri, 07 Dec 2007 21:08:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.sematopia.com/?p=216#comment-43916</guid>
		<description>Does not seem to be working and tried everything and still does not work.
The first page load serializes ok. The second page load, where the first part of if statement is processed, shows up blank. How does static variables from first page get loaded on unserializing?</description>
		<content:encoded><![CDATA[<p>Does not seem to be working and tried everything and still does not work.<br />
The first page load serializes ok. The second page load, where the first part of if statement is processed, shows up blank. How does static variables from first page get loaded on unserializing?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
