<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>Comments on snippet: 'Convert Array to Object, infinite dimensions'</title>
<link>http://snipplr.com</link>
<description>Snipplr comments feed'</description>
<language>en-us</language>
<pubDate>Sun, 19 May 2013 02:30:29 GMT</pubDate>
<item>
<title>bugfix said on 10/21/11</title>
<link>http://snipplr.com/view/8770/convert-array-to-object-infinite-dimensions/</link>
<description><![CDATA[ I  want to "highlight" the line, sorry of the bad paste ! ]]></description>
<pubDate>Fri, 21 Oct 2011 01:31:28 GMT</pubDate>
<guid>http://snipplr.com/view/8770/convert-array-to-object-infinite-dimensions/</guid>
</item>
<item>
<title>bugfix said on 10/21/11</title>
<link>http://snipplr.com/view/8770/convert-array-to-object-infinite-dimensions/</link>
<description><![CDATA[ Hello

Good work it is very useful.

However, maybe the is a gap that could be a problem : when we have an array in a standard object, this array will not be converted because the script will call itself only if the container is an array.

So we can fix it as this :

[...]
foreach ($array as $k => $v)
{
  if (is_array($v))       $return->$k = $this->bindArrayToObject($v);
  else if (is_object($v)) $return->$k = $this->bindArrayToObject($v); // BUG FIX
  else  $return->$k = $v;
}
[...]

Now, we analyse the objects too, and if they contains arrays, they will be converted too.

if (is_array($v) || is_object($v)) is better but I want to if (is_array($v)) the line of the bugfix :)

Hope it's help. ]]></description>
<pubDate>Fri, 21 Oct 2011 01:29:47 GMT</pubDate>
<guid>http://snipplr.com/view/8770/convert-array-to-object-infinite-dimensions/</guid>
</item>
<item>
<title>purefusion said on 10/24/08</title>
<link>http://snipplr.com/view/8770/convert-array-to-object-infinite-dimensions/</link>
<description><![CDATA[ You may also be able to get away with doing: $obj = (object)$arr; 
Or as a specific class: $obj = (YourClass)$array; ]]></description>
<pubDate>Fri, 24 Oct 2008 16:24:57 GMT</pubDate>
<guid>http://snipplr.com/view/8770/convert-array-to-object-infinite-dimensions/</guid>
</item>
</channel>
</rss>