<?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&#8217;s mystical __set_state method</title>
	<atom:link href="http://www.thoughtlabs.com/2008/02/02/phps-mystical-__set_state-method/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.thoughtlabs.com/2008/02/02/phps-mystical-__set_state-method/</link>
	<description>A blog about Social Media by John Maver and Cappy Popp</description>
	<lastBuildDate>Fri, 06 Jan 2012 13:01:37 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: the_dude_abides</title>
		<link>http://www.thoughtlabs.com/2008/02/02/phps-mystical-__set_state-method/comment-page-1/#comment-432</link>
		<dc:creator>the_dude_abides</dc:creator>
		<pubDate>Wed, 24 Feb 2010 22:03:20 +0000</pubDate>
		<guid isPermaLink="false">http://innercircle.thoughtlabs.com/blogs/2008/02/02/phps-mystical-__set_state-method/#comment-432</guid>
		<description>UPDATE: Instead of using a foreach loop in stdClassHelper::__set_state() you can compress that code into a single line:
&lt;br&gt;
&lt;br&gt;return (object) $array;</description>
		<content:encoded><![CDATA[<p>UPDATE: Instead of using a foreach loop in stdClassHelper::__set_state() you can compress that code into a single line:</p>
<p>return (object) $array;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: the_dude_abides</title>
		<link>http://www.thoughtlabs.com/2008/02/02/phps-mystical-__set_state-method/comment-page-1/#comment-431</link>
		<dc:creator>the_dude_abides</dc:creator>
		<pubDate>Wed, 24 Feb 2010 21:02:18 +0000</pubDate>
		<guid isPermaLink="false">http://innercircle.thoughtlabs.com/blogs/2008/02/02/phps-mystical-__set_state-method/#comment-431</guid>
		<description>// This is an example of how you can use __set_state() with a stdClass object in PHP 5
&lt;br&gt;$myStdClass = new stdClass();
&lt;br&gt;$myStdClass-&gt;foo = &#039;bar&#039;;
&lt;br&gt;echo &#039;$myStdClass = &#039; . print_r($myStdClass, true) . &quot;n&quot;;
&lt;br&gt;
&lt;br&gt;// The below line outputs:  stdClass::__set_state(array(&#039;foo&#039; =&gt; &#039;bar&#039;,))
&lt;br&gt;// Actually calling stdClass::__set_state() in PHP 5 will produce a fatal error.
&lt;br&gt;echo &#039;var_export = &#039; . var_export($myStdClass, true) . &quot;nn&quot;;
&lt;br&gt;
&lt;br&gt;// Replace the text &quot;stdClass::&quot; with &quot;stdClassHelper::&quot; like so:
&lt;br&gt;$myNewStdClass = stdClassHelper::__set_state(array(&#039;foo&#039; =&gt; &#039;bar&#039;,));
&lt;br&gt;
&lt;br&gt;// Success!
&lt;br&gt;echo &#039;$myNewStdClass = &#039; . print_r($myNewStdClass, true);
&lt;br&gt;
&lt;br&gt;// Here&#039;s how it&#039;s done.
&lt;br&gt;class stdClassHelper
&lt;br&gt;{
&lt;br&gt;	public static function __set_state(array $array)
&lt;br&gt;	{
&lt;br&gt;		$stdClass = new stdClass();
&lt;br&gt;		foreach ($array as $key =&gt; $value)
&lt;br&gt;		{
&lt;br&gt;			$stdClass-&gt;$key = $value;
&lt;br&gt;		}
&lt;br&gt;		return $stdClass;
&lt;br&gt;	}
&lt;br&gt;}</description>
		<content:encoded><![CDATA[<p>// This is an example of how you can use __set_state() with a stdClass object in PHP 5<br />
<br />$myStdClass = new stdClass();<br />
<br />$myStdClass-&gt;foo = &#39;bar&#39;;<br />
<br />echo &#39;$myStdClass = &#39; . print_r($myStdClass, true) . &#8220;n&#8221;;</p>
<p>// The below line outputs:  stdClass::__set_state(array(&#39;foo&#39; =&gt; &#39;bar&#39;,))<br />
<br />// Actually calling stdClass::__set_state() in PHP 5 will produce a fatal error.<br />
<br />echo &#39;var_export = &#39; . var_export($myStdClass, true) . &#8220;nn&#8221;;</p>
<p>// Replace the text &#8220;stdClass::&#8221; with &#8220;stdClassHelper::&#8221; like so:<br />
<br />$myNewStdClass = stdClassHelper::__set_state(array(&#39;foo&#39; =&gt; &#39;bar&#39;,));</p>
<p>// Success!<br />
<br />echo &#39;$myNewStdClass = &#39; . print_r($myNewStdClass, true);</p>
<p>// Here&#39;s how it&#39;s done.<br />
<br />class stdClassHelper<br />
<br />{<br />
<br />	public static function __set_state(array $array)<br />
<br />	{<br />
<br />		$stdClass = new stdClass();<br />
<br />		foreach ($array as $key =&gt; $value)<br />
<br />		{<br />
<br />			$stdClass-&gt;$key = $value;<br />
<br />		}<br />
<br />		return $stdClass;<br />
<br />	}<br />
<br />}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: the_dude_abides</title>
		<link>http://www.thoughtlabs.com/2008/02/02/phps-mystical-__set_state-method/comment-page-1/#comment-415</link>
		<dc:creator>the_dude_abides</dc:creator>
		<pubDate>Wed, 24 Feb 2010 17:03:20 +0000</pubDate>
		<guid isPermaLink="false">http://innercircle.thoughtlabs.com/blogs/2008/02/02/phps-mystical-__set_state-method/#comment-415</guid>
		<description>UPDATE: Instead of using a foreach loop in stdClassHelper::__set_state() you can compress that code into a single line:&lt;br&gt;&lt;br&gt;return (object) $array;</description>
		<content:encoded><![CDATA[<p>UPDATE: Instead of using a foreach loop in stdClassHelper::__set_state() you can compress that code into a single line:</p>
<p>return (object) $array;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: the_dude_abides</title>
		<link>http://www.thoughtlabs.com/2008/02/02/phps-mystical-__set_state-method/comment-page-1/#comment-414</link>
		<dc:creator>the_dude_abides</dc:creator>
		<pubDate>Wed, 24 Feb 2010 16:02:18 +0000</pubDate>
		<guid isPermaLink="false">http://innercircle.thoughtlabs.com/blogs/2008/02/02/phps-mystical-__set_state-method/#comment-414</guid>
		<description>// This is an example of how you can use __set_state() with a stdClass object in PHP 5&lt;br&gt;$myStdClass = new stdClass();&lt;br&gt;$myStdClass-&gt;foo = &#039;bar&#039;;&lt;br&gt;echo &#039;$myStdClass = &#039; . print_r($myStdClass, true) . &quot;n&quot;;&lt;br&gt;&lt;br&gt;// The below line outputs:  stdClass::__set_state(array(&#039;foo&#039; =&gt; &#039;bar&#039;,))&lt;br&gt;// Actually calling stdClass::__set_state() in PHP 5 will produce a fatal error.&lt;br&gt;echo &#039;var_export = &#039; . var_export($myStdClass, true) . &quot;nn&quot;;&lt;br&gt;&lt;br&gt;// Replace the text &quot;stdClass::&quot; with &quot;stdClassHelper::&quot; like so:&lt;br&gt;$myNewStdClass = stdClassHelper::__set_state(array(&#039;foo&#039; =&gt; &#039;bar&#039;,));&lt;br&gt;&lt;br&gt;// Success!&lt;br&gt;echo &#039;$myNewStdClass = &#039; . print_r($myNewStdClass, true);&lt;br&gt;&lt;br&gt;// Here&#039;s how it&#039;s done.&lt;br&gt;class stdClassHelper&lt;br&gt;{&lt;br&gt;	public static function __set_state(array $array)&lt;br&gt;	{&lt;br&gt;		$stdClass = new stdClass();&lt;br&gt;		foreach ($array as $key =&gt; $value)&lt;br&gt;		{&lt;br&gt;			$stdClass-&gt;$key = $value;&lt;br&gt;		}&lt;br&gt;		return $stdClass;&lt;br&gt;	}&lt;br&gt;}</description>
		<content:encoded><![CDATA[<p>// This is an example of how you can use __set_state() with a stdClass object in PHP 5<br />$myStdClass = new stdClass();<br />$myStdClass-&gt;foo = &#39;bar&#39;;<br />echo &#39;$myStdClass = &#39; . print_r($myStdClass, true) . &#8220;n&#8221;;</p>
<p>// The below line outputs:  stdClass::__set_state(array(&#39;foo&#39; =&gt; &#39;bar&#39;,))<br />// Actually calling stdClass::__set_state() in PHP 5 will produce a fatal error.<br />echo &#39;var_export = &#39; . var_export($myStdClass, true) . &#8220;nn&#8221;;</p>
<p>// Replace the text &#8220;stdClass::&#8221; with &#8220;stdClassHelper::&#8221; like so:<br />$myNewStdClass = stdClassHelper::__set_state(array(&#39;foo&#39; =&gt; &#39;bar&#39;,));</p>
<p>// Success!<br />echo &#39;$myNewStdClass = &#39; . print_r($myNewStdClass, true);</p>
<p>// Here&#39;s how it&#39;s done.<br />class stdClassHelper<br />{<br />	public static function __set_state(array $array)<br />	{<br />		$stdClass = new stdClass();<br />		foreach ($array as $key =&gt; $value)<br />		{<br />			$stdClass-&gt;$key = $value;<br />		}<br />		return $stdClass;<br />	}<br />}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: delcroixenator</title>
		<link>http://www.thoughtlabs.com/2008/02/02/phps-mystical-__set_state-method/comment-page-1/#comment-411</link>
		<dc:creator>delcroixenator</dc:creator>
		<pubDate>Sun, 14 Feb 2010 22:12:52 +0000</pubDate>
		<guid isPermaLink="false">http://innercircle.thoughtlabs.com/blogs/2008/02/02/phps-mystical-__set_state-method/#comment-411</guid>
		<description>thank you for this article. Very useful for me. E.D</description>
		<content:encoded><![CDATA[<p>thank you for this article. Very useful for me. E.D</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: reeze</title>
		<link>http://www.thoughtlabs.com/2008/02/02/phps-mystical-__set_state-method/comment-page-1/#comment-381</link>
		<dc:creator>reeze</dc:creator>
		<pubDate>Thu, 02 Jul 2009 04:08:31 +0000</pubDate>
		<guid isPermaLink="false">http://innercircle.thoughtlabs.com/blogs/2008/02/02/phps-mystical-__set_state-method/#comment-381</guid>
		<description>thank you for your explain, that&#039;s helpful,thx!</description>
		<content:encoded><![CDATA[<p>thank you for your explain, that&#39;s helpful,thx!</p>
]]></content:encoded>
	</item>
</channel>
</rss>

