<?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: I called Zend_Json::encode(), so WTH are all my properties?</title> <atom:link href="http://blog.calevans.com/2008/02/21/zend_jsonencode-and-wth-are-all-my-properties/feed/" rel="self" type="application/rss+xml" /><link>http://blog.calevans.com/2008/02/21/zend_jsonencode-and-wth-are-all-my-properties/</link> <description>Lint I find in my mind&#039;s belly-button.</description> <lastBuildDate>Tue, 16 Mar 2010 03:19:09 +0000</lastBuildDate> <generator>http://wordpress.org/?v=2.9.2</generator> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <atom:link rel="hub" href="http://pubsubhubbub.appspot.com" /> <atom:link rel="hub" href="http://superfeedr.com/hubbub" /> <item><title>By: Cal Evans</title><link>http://blog.calevans.com/2008/02/21/zend_jsonencode-and-wth-are-all-my-properties/comment-page-1/#comment-56511</link> <dc:creator>Cal Evans</dc:creator> <pubDate>Tue, 26 Feb 2008 01:11:40 +0000</pubDate> <guid isPermaLink="false">http://blog.calevans.com/2008/02/21/zend_jsonencode-and-wth-are-all-my-properties/#comment-56511</guid> <description>ZOMG!Hey, never apologize for doing a better job.  I knew array_flip() existed but don&#039;t think I&#039;ve ever used it and I didn&#039;t even know array_diff_key() was there.Thanks, I&#039;ve updated my code.=C=</description> <content:encoded><![CDATA[<p>ZOMG!</p><p>Hey, never apologize for doing a better job.  I knew array_flip() existed but don&#8217;t think I&#8217;ve ever used it and I didn&#8217;t even know array_diff_key() was there.</p><p>Thanks, I&#8217;ve updated my code.</p><p>=C=</p> ]]></content:encoded> </item> <item><title>By: PrettyCoder</title><link>http://blog.calevans.com/2008/02/21/zend_jsonencode-and-wth-are-all-my-properties/comment-page-1/#comment-56462</link> <dc:creator>PrettyCoder</dc:creator> <pubDate>Mon, 25 Feb 2008 09:00:33 +0000</pubDate> <guid isPermaLink="false">http://blog.calevans.com/2008/02/21/zend_jsonencode-and-wth-are-all-my-properties/#comment-56462</guid> <description>public function getProperties($skip = array()) { return array_diff_key($this-&gt;_data, array_flip($skip)); }Sorry, couldn&#039;t resist.</description> <content:encoded><![CDATA[<p>public function getProperties($skip = array())<br /> {<br /> return array_diff_key($this-&gt;_data, array_flip($skip));<br /> }</p><p>Sorry, couldn&#8217;t resist.</p> ]]></content:encoded> </item> <item><title>By: Cal Evans</title><link>http://blog.calevans.com/2008/02/21/zend_jsonencode-and-wth-are-all-my-properties/comment-page-1/#comment-56363</link> <dc:creator>Cal Evans</dc:creator> <pubDate>Sun, 24 Feb 2008 14:56:14 +0000</pubDate> <guid isPermaLink="false">http://blog.calevans.com/2008/02/21/zend_jsonencode-and-wth-are-all-my-properties/#comment-56363</guid> <description>reHi fangel!First, I think I may have explained it poorly. Having an iterator does not solve the problem.  However, since ALL we are transferring to the front-end is properties, having a method that I can quickly pull out the array of properties and json encode THAT does solve the problem.Second, json_encode &lt;strong&gt;does&lt;/strong&gt; work the way most of us would expect it to. It iterates through the public properties and encodes them.  The mistake I made was to make my array of properties protected...actually, it wasn&#039;t a mistake, it was the right thing to do for the way I was coding.There is no magic to getProperties() and I would never expect json_encode or Zend_Json::encode() to recognize that method and use it.  I was a solution for the problem I had.Thanks for writing.=C=</description> <content:encoded><![CDATA[<p>reHi fangel!</p><p>First, I think I may have explained it poorly. Having an iterator does not solve the problem.  However, since ALL we are transferring to the front-end is properties, having a method that I can quickly pull out the array of properties and json encode THAT does solve the problem.</p><p>Second, json_encode <strong>does</strong> work the way most of us would expect it to. It iterates through the public properties and encodes them.  The mistake I made was to make my array of properties protected&#8230;actually, it wasn&#8217;t a mistake, it was the right thing to do for the way I was coding.</p><p>There is no magic to getProperties() and I would never expect json_encode or Zend_Json::encode() to recognize that method and use it.  I was a solution for the problem I had.</p><p>Thanks for writing.</p><p>=C=</p> ]]></content:encoded> </item> <item><title>By: fangel</title><link>http://blog.calevans.com/2008/02/21/zend_jsonencode-and-wth-are-all-my-properties/comment-page-1/#comment-56330</link> <dc:creator>fangel</dc:creator> <pubDate>Sun, 24 Feb 2008 10:34:27 +0000</pubDate> <guid isPermaLink="false">http://blog.calevans.com/2008/02/21/zend_jsonencode-and-wth-are-all-my-properties/#comment-56330</guid> <description>I did some tests and, if using json_encode, having a Iterator for the object doesn&#039;t help out. So no, that wouldn&#039;t help on you problem..I, personally, think I would prefer it to actually work. If you expose a iterator for you object, I would expect any code that needs access to the members of this class to use the iterator. Instead it uses some &quot;magic&quot; code that finds the public members. Exposing a Iterator, in my mind, means &quot;if you need to loop though the variables in this class - use this Iterator&quot;. But json_encode() doesn&#039;t do this..-f</description> <content:encoded><![CDATA[<p>I did some tests and, if using json_encode, having a Iterator for the object doesn&#8217;t help out.<br /> So no, that wouldn&#8217;t help on you problem..</p><p>I, personally, think I would prefer it to actually work. If you expose a iterator for you object, I would expect any code that needs access to the members of this class to use the iterator. Instead it uses some &#8220;magic&#8221; code that finds the public members.<br /> Exposing a Iterator, in my mind, means &#8220;if you need to loop though the variables in this class &#8211; use this Iterator&#8221;. But json_encode() doesn&#8217;t do this..</p><p>-f</p> ]]></content:encoded> </item> <item><title>By: Cal Evans</title><link>http://blog.calevans.com/2008/02/21/zend_jsonencode-and-wth-are-all-my-properties/comment-page-1/#comment-56127</link> <dc:creator>Cal Evans</dc:creator> <pubDate>Fri, 22 Feb 2008 21:00:13 +0000</pubDate> <guid isPermaLink="false">http://blog.calevans.com/2008/02/21/zend_jsonencode-and-wth-are-all-my-properties/#comment-56127</guid> <description>Hi Deminy,Thanks for posting!Actually no, it&#039;s that way on purpose but that code was scraped from my real class to build the example.  In the real code, I build the array with all the elements blank in the __construct.  This way, I can&#039;t accidentally add new properties to the object that would cause me problems later.  I&#039;ll correct the example.  Thanks for pointing that out.=C=</description> <content:encoded><![CDATA[<p>Hi Deminy,</p><p>Thanks for posting!</p><p>Actually no, it&#8217;s that way on purpose but that code was scraped from my real class to build the example.  In the real code, I build the array with all the elements blank in the __construct.  This way, I can&#8217;t accidentally add new properties to the object that would cause me problems later.  I&#8217;ll correct the example.  Thanks for pointing that out.</p><p>=C=</p> ]]></content:encoded> </item> <item><title>By: deminy</title><link>http://blog.calevans.com/2008/02/21/zend_jsonencode-and-wth-are-all-my-properties/comment-page-1/#comment-56124</link> <dc:creator>deminy</dc:creator> <pubDate>Fri, 22 Feb 2008 20:37:54 +0000</pubDate> <guid isPermaLink="false">http://blog.calevans.com/2008/02/21/zend_jsonencode-and-wth-are-all-my-properties/#comment-56124</guid> <description>Well... Inside the magic function __set() you defined, I think if (isset($this-&gt;_data[$index])) { should be if (!isset($this-&gt;_data[$index])) {</description> <content:encoded><![CDATA[<p>Well&#8230; Inside the magic function __set() you defined, I think<br /> if (isset($this-&gt;_data[$index])) {<br /> should be<br /> if (!isset($this-&gt;_data[$index])) {</p> ]]></content:encoded> </item> <item><title>By: PHPDeveloper.org</title><link>http://blog.calevans.com/2008/02/21/zend_jsonencode-and-wth-are-all-my-properties/comment-page-1/#comment-56102</link> <dc:creator>PHPDeveloper.org</dc:creator> <pubDate>Fri, 22 Feb 2008 17:18:39 +0000</pubDate> <guid isPermaLink="false">http://blog.calevans.com/2008/02/21/zend_jsonencode-and-wth-are-all-my-properties/#comment-56102</guid> <description>&lt;strong&gt;Cal Evans&#039; Blog: I called Zend_Json::encode(), so WTH are all my properties?...&lt;/strong&gt;In dealing with a little JSON encoding and objects in a ......</description> <content:encoded><![CDATA[<p><strong>Cal Evans&#8217; Blog: I called Zend_Json::encode(), so WTH are all my properties?&#8230;</strong></p><p>In dealing with a little JSON encoding and objects in a &#8230;&#8230;</p> ]]></content:encoded> </item> <item><title>By: Cal Evans</title><link>http://blog.calevans.com/2008/02/21/zend_jsonencode-and-wth-are-all-my-properties/comment-page-1/#comment-56080</link> <dc:creator>Cal Evans</dc:creator> <pubDate>Fri, 22 Feb 2008 13:32:29 +0000</pubDate> <guid isPermaLink="false">http://blog.calevans.com/2008/02/21/zend_jsonencode-and-wth-are-all-my-properties/#comment-56080</guid> <description>Hi fangel!Thanks for leaving a comment.IIRC, and I&#039;ll be honest in saying I&#039;ve not looked at the code in a while, Zend_Json uses the naive json_encode method if it&#039;s available. In my case it was. So while my post was specifically about Zend_Json, it applies as well to json_encode().Also, honestly, I wouldn&#039;t want it to operate any other way.  In hindsight, this is the proper way for it to work. I mark properties protected for a reason and it&#039;s real easy to expose them if I need to.That having been said, yes, if I&#039;m implementing JSON encoding nativly in PHP, it would be possible to do it your way and be able to get a more complete representation of the object.Thanks again for taking the time to lave a comment.=C=</description> <content:encoded><![CDATA[<p>Hi fangel!</p><p>Thanks for leaving a comment.</p><p>IIRC, and I&#8217;ll be honest in saying I&#8217;ve not looked at the code in a while, Zend_Json uses the naive json_encode method if it&#8217;s available. In my case it was. So while my post was specifically about Zend_Json, it applies as well to json_encode().</p><p>Also, honestly, I wouldn&#8217;t want it to operate any other way.  In hindsight, this is the proper way for it to work. I mark properties protected for a reason and it&#8217;s real easy to expose them if I need to.</p><p>That having been said, yes, if I&#8217;m implementing JSON encoding nativly in PHP, it would be possible to do it your way and be able to get a more complete representation of the object.</p><p>Thanks again for taking the time to lave a comment.</p><p>=C=</p> ]]></content:encoded> </item> <item><title>By: fangel</title><link>http://blog.calevans.com/2008/02/21/zend_jsonencode-and-wth-are-all-my-properties/comment-page-1/#comment-56055</link> <dc:creator>fangel</dc:creator> <pubDate>Fri, 22 Feb 2008 08:14:34 +0000</pubDate> <guid isPermaLink="false">http://blog.calevans.com/2008/02/21/zend_jsonencode-and-wth-are-all-my-properties/#comment-56055</guid> <description>A theory: Implementing a SPL Iterator for your object will fix the issue.I don&#039;t know how Zend_Json::encode works, but if it does a foreach($obj ..) then adding a simple SPI Iterator interface to your object will make it work correctly.. If it uses reflections I&#039;m not sure what will happen.. Worth a shot imho..XOXO</description> <content:encoded><![CDATA[<p>A theory: Implementing a SPL Iterator for your object will fix the issue.</p><p>I don&#8217;t know how Zend_Json::encode works, but if it does a foreach($obj ..) then adding a simple SPI Iterator interface to your object will make it work correctly.. If it uses reflections I&#8217;m not sure what will happen..<br /> Worth a shot imho..</p><p>XOXO</p> ]]></content:encoded> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (user agent is rejected)
Database Caching 17/37 queries in 0.072 seconds using disk

Served from: blog.calevans.com @ 2010-03-16 19:49:17 -->