<?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: How to Expose PHP&#8217;s Private Parts</title>
	<atom:link href="http://www.sitepoint.com/blogs/2008/11/11/how-to-expose-phps-private-parts/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sitepoint.com/blogs/2008/11/11/how-to-expose-phps-private-parts/</link>
	<description>News, opinion, and fresh thinking for web developers and designers. The official podcast of sitepoint.com.</description>
	<lastBuildDate>Sun, 08 Nov 2009 18:10:55 -0500</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: TerrorKalle</title>
		<link>http://www.sitepoint.com/blogs/2008/11/11/how-to-expose-phps-private-parts/comment-page-1/#comment-839071</link>
		<dc:creator>TerrorKalle</dc:creator>
		<pubDate>Tue, 25 Nov 2008 17:08:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=3169#comment-839071</guid>
		<description>Casting an object to an array like stated above will expose its private properties aswell as its private properties. Its quite simple:

&lt;a href=&quot;http://www.phpfi.com/382350&quot; rel=&quot;nofollow&quot;&gt;http://www.phpfi.com/382350&lt;/a&gt;

:)</description>
		<content:encoded><![CDATA[<p>Casting an object to an array like stated above will expose its private properties aswell as its private properties. Its quite simple:</p>
<p><a href="http://www.phpfi.com/382350" rel="nofollow">http://www.phpfi.com/382350</a></p>
<p>:)</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Duh.</title>
		<link>http://www.sitepoint.com/blogs/2008/11/11/how-to-expose-phps-private-parts/comment-page-1/#comment-831339</link>
		<dc:creator>Duh.</dc:creator>
		<pubDate>Sat, 15 Nov 2008 21:00:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=3169#comment-831339</guid>
		<description>$arr = (array)$object;
var_dump($arr);

// Win</description>
		<content:encoded><![CDATA[<p>$arr = (array)$object;<br />
var_dump($arr);</p>
<p>// Win</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Ren</title>
		<link>http://www.sitepoint.com/blogs/2008/11/11/how-to-expose-phps-private-parts/comment-page-1/#comment-825826</link>
		<dc:creator>Ren</dc:creator>
		<pubDate>Thu, 13 Nov 2008 16:49:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=3169#comment-825826</guid>
		<description>The (array) casting of objects is useful. One particular use was to map objects to an array of parameters for prepared sql.

&lt;code&gt;
class Person
{
   protected $id;
   public $firstName;
   public $lastName;

   function __construct($firstName, $lastName, $id = null) 
   {
      $this-&gt;id = $id; 
      $this-&gt;firstName = $firstName; 
      $this-&gt;lastName = $lastName; 
   }
}

$person = new Person(&#039;Homer&#039;, &#039;Simpson&#039;);

$map = array(
   &quot;*id&quot; =&gt; &#039;id&#039;,	
   &quot;firstName&quot; =&gt; &#039;firstName&#039;,
   &quot;lastName&quot; =&gt; &#039;lastName&#039;);

$params = array_combine($map, array_intersect_key((array)$person, $map));

var_dump($params);
&lt;/code&gt;

No idea how your supposed to get code displaying nicely here</description>
		<content:encoded><![CDATA[<p>The (array) casting of objects is useful. One particular use was to map objects to an array of parameters for prepared sql.</p>
<code>
class Person
{
   protected $id;
   public $firstName;
   public $lastName;

   function __construct($firstName, $lastName, $id = null) 
   {
      $this-&gt;id = $id; 
      $this-&gt;firstName = $firstName; 
      $this-&gt;lastName = $lastName; 
   }
}

$person = new Person('Homer', 'Simpson');

$map = array(
   "*id" =&gt; 'id',	
   "firstName" =&gt; 'firstName',
   "lastName" =&gt; 'lastName');

$params = array_combine($map, array_intersect_key((array)$person, $map));

var_dump($params);
</code>
<p>No idea how your supposed to get code displaying nicely here</p>]]></content:encoded>
	</item>
	<item>
		<title>By: mattymcg</title>
		<link>http://www.sitepoint.com/blogs/2008/11/11/how-to-expose-phps-private-parts/comment-page-1/#comment-825400</link>
		<dc:creator>mattymcg</dc:creator>
		<pubDate>Wed, 12 Nov 2008 23:56:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=3169#comment-825400</guid>
		<description>Thanks everyone for being considerate and professional when posting here—getting personal doesn&#039;t help anyone. Also worth noting that we have a &quot;comment preview&quot;, so you can check what your comments look like before posting. I&#039;ve cleaned up a few people&#039;s comments. Hope that helps!</description>
		<content:encoded><![CDATA[<p>Thanks everyone for being considerate and professional when posting here—getting personal doesn&#8217;t help anyone. Also worth noting that we have a &#8220;comment preview&#8221;, so you can check what your comments look like before posting. I&#8217;ve cleaned up a few people&#8217;s comments. Hope that helps!</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Nick</title>
		<link>http://www.sitepoint.com/blogs/2008/11/11/how-to-expose-phps-private-parts/comment-page-1/#comment-825385</link>
		<dc:creator>Nick</dc:creator>
		<pubDate>Wed, 12 Nov 2008 23:25:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=3169#comment-825385</guid>
		<description>My apologies, honestly, not trying to be rude.  If it&#039;s rude to deconstruct a technical article for accuracy, then we might as well all go home and take up farming for a living.

I understand that I misread the article and you are simply trying to show that parsing a serialized string is easier than formatting the output from print_r().

That being the case, I&#039;d like to re-emphasize that this kind of debugging is aided and enhanced greatly by the xdebug extension, which comes with a nice feature to format the var_dump() output for you with nice HTML and pretty colors.  (among many other much more powerful features.)</description>
		<content:encoded><![CDATA[<p>My apologies, honestly, not trying to be rude.  If it&#8217;s rude to deconstruct a technical article for accuracy, then we might as well all go home and take up farming for a living.</p>
<p>I understand that I misread the article and you are simply trying to show that parsing a serialized string is easier than formatting the output from print_r().</p>
<p>That being the case, I&#8217;d like to re-emphasize that this kind of debugging is aided and enhanced greatly by the xdebug extension, which comes with a nice feature to format the var_dump() output for you with nice HTML and pretty colors.  (among many other much more powerful features.)</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Troels Knak-Nielsen</title>
		<link>http://www.sitepoint.com/blogs/2008/11/11/how-to-expose-phps-private-parts/comment-page-1/#comment-825373</link>
		<dc:creator>Troels Knak-Nielsen</dc:creator>
		<pubDate>Wed, 12 Nov 2008 23:01:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=3169#comment-825373</guid>
		<description>&lt;blockquote&gt;Don’t get reflexively defensive. Correct me if I’m wrong, but the basis of this article is: print_r() does not print out private and protected variables of an object. Hence the need for this class you wrote. Correct?&lt;/blockquote&gt;
Defensive? I find your tone borderline rude, but to let you have the benefit of doubt, I&#039;ll answer none the less.

No, my assertion was the opposite -- Namely that &lt;code&gt;print_r&lt;/code&gt; is able to do something that is impossible through the reflection API -- At least until 5.3.0 comes out. What I wanted to do, was to generate some pretty HTML representation of variables, rather than the text-based output from &lt;code&gt;print_r&lt;/code&gt;. Something similar to &lt;a href=&quot;http://dbug.ospinto.com/&quot; rel=&quot;nofollow&quot;&gt;this&lt;/a&gt; for example.</description>
		<content:encoded><![CDATA[<blockquote><p>Don’t get reflexively defensive. Correct me if I’m wrong, but the basis of this article is: print_r() does not print out private and protected variables of an object. Hence the need for this class you wrote. Correct?</p></blockquote>
<p>Defensive? I find your tone borderline rude, but to let you have the benefit of doubt, I&#8217;ll answer none the less.</p>
<p>No, my assertion was the opposite &#8212; Namely that <code>print_r</code> is able to do something that is impossible through the reflection API &#8212; At least until 5.3.0 comes out. What I wanted to do, was to generate some pretty HTML representation of variables, rather than the text-based output from <code>print_r</code>. Something similar to <a href="http://dbug.ospinto.com/" rel="nofollow">this</a> for example.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Nick</title>
		<link>http://www.sitepoint.com/blogs/2008/11/11/how-to-expose-phps-private-parts/comment-page-1/#comment-825366</link>
		<dc:creator>Nick</dc:creator>
		<pubDate>Wed, 12 Nov 2008 22:40:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=3169#comment-825366</guid>
		<description>My apologies about the formatting there.</description>
		<content:encoded><![CDATA[<p>My apologies about the formatting there.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Nick</title>
		<link>http://www.sitepoint.com/blogs/2008/11/11/how-to-expose-phps-private-parts/comment-page-1/#comment-825365</link>
		<dc:creator>Nick</dc:creator>
		<pubDate>Wed, 12 Nov 2008 22:38:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=3169#comment-825365</guid>
		<description>Don&#039;t get reflexively defensive.  Correct me if I&#039;m wrong, but the basis of this article is:  &lt;code&gt;print_r()&lt;/code&gt; does not print out private and protected variables of an object.  Hence the need for this class you wrote.  Correct?

I was pointing out that this assertion about &lt;code&gt;print_r()&lt;/code&gt; is not true.

Let&#039;s try an example, this will be using PHP 5.2.4:
&lt;pre&gt;&lt;code class=&#039;php&#039;&gt;
class AClass
{
    protected $pro2;
    private $pri2;
    function __construct() {
        $this-&gt;pro2 = &quot;parent class protected var&quot;;
        $this-&gt;pri2 = &quot;parent class private var&quot;;
    }
}

class MyClass extends AClass
{
    public $pub;
    private $pri;
    protected $pro;
    function __construct() {
        parent::__construct();
        $this-&gt;pub = &quot;public var&quot;;
        $this-&gt;pri = &quot;private var&quot;;
        $this-&gt;pro = &quot;protected var&quot;;
    }
}

$c = new MyClass();

print_r($c);
exit;

MyClass Object
(
    [pub] =&gt; public var
    [pri:private] =&gt; private var
    [pro:protected] =&gt; protected var
    [pro2:protected] =&gt; parent class protected var
    [pri2:private] =&gt; parent class private var
)&lt;/code&gt;&lt;/pre&gt;

Explain how that is substantively different than the output of your class&#039;s &lt;code&gt;export()&lt;/code&gt; method:

&lt;pre&gt;&lt;code class=&#039;php&#039;&gt;Array
(
    [type] =&gt; object
    [id] =&gt; 1
    [class] =&gt; MyClass
    [value] =&gt; Array
        (
            [pub] =&gt; Array
                (
                    [type] =&gt; string
                    [id] =&gt; 2
                    [value] =&gt; public var
                )

            [private:pri] =&gt; Array
                (
                    [type] =&gt; string
                    [id] =&gt; 3
                    [value] =&gt; private var
                )

            [protected:pro] =&gt; Array
                (
                    [type] =&gt; string
                    [id] =&gt; 4
                    [value] =&gt; protected var
                )

            [protected:pro2] =&gt; Array
                (
                    [type] =&gt; string
                    [id] =&gt; 5
                    [value] =&gt; parent class protected var
                )

            [private:pri2] =&gt; Array
                (
                    [type] =&gt; string
                    [id] =&gt; 6
                    [value] =&gt; parent class private var
                )

        )

)&lt;/code&gt;&lt;/pre&gt;
</description>
		<content:encoded><![CDATA[<p>Don&#8217;t get reflexively defensive.  Correct me if I&#8217;m wrong, but the basis of this article is:  <code>print_r()</code> does not print out private and protected variables of an object.  Hence the need for this class you wrote.  Correct?</p>
<p>I was pointing out that this assertion about <code>print_r()</code> is not true.</p>
<p>Let&#8217;s try an example, this will be using PHP 5.2.4:</p>
<pre><code class='php'>
class AClass
{
    protected $pro2;
    private $pri2;
    function __construct() {
        $this-&gt;pro2 = "parent class protected var";
        $this-&gt;pri2 = "parent class private var";
    }
}

class MyClass extends AClass
{
    public $pub;
    private $pri;
    protected $pro;
    function __construct() {
        parent::__construct();
        $this-&gt;pub = "public var";
        $this-&gt;pri = "private var";
        $this-&gt;pro = "protected var";
    }
}

$c = new MyClass();

print_r($c);
exit;

MyClass Object
(
    [pub] =&gt; public var
    [pri:private] =&gt; private var
    [pro:protected] =&gt; protected var
    [pro2:protected] =&gt; parent class protected var
    [pri2:private] =&gt; parent class private var
)</code></pre>
<p>Explain how that is substantively different than the output of your class&#8217;s <code>export()</code> method:</p>
<pre><code class='php'>Array
(
    [type] =&gt; object
    [id] =&gt; 1
    [class] =&gt; MyClass
    [value] =&gt; Array
        (
            [pub] =&gt; Array
                (
                    [type] =&gt; string
                    [id] =&gt; 2
                    [value] =&gt; public var
                )

            [private:pri] =&gt; Array
                (
                    [type] =&gt; string
                    [id] =&gt; 3
                    [value] =&gt; private var
                )

            [protected:pro] =&gt; Array
                (
                    [type] =&gt; string
                    [id] =&gt; 4
                    [value] =&gt; protected var
                )

            [protected:pro2] =&gt; Array
                (
                    [type] =&gt; string
                    [id] =&gt; 5
                    [value] =&gt; parent class protected var
                )

            [private:pri2] =&gt; Array
                (
                    [type] =&gt; string
                    [id] =&gt; 6
                    [value] =&gt; parent class private var
                )

        )

)</code></pre>]]></content:encoded>
	</item>
	<item>
		<title>By: Troels Knak-Nielsen</title>
		<link>http://www.sitepoint.com/blogs/2008/11/11/how-to-expose-phps-private-parts/comment-page-1/#comment-825359</link>
		<dc:creator>Troels Knak-Nielsen</dc:creator>
		<pubDate>Wed, 12 Nov 2008 22:23:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=3169#comment-825359</guid>
		<description>@Ken Guest
Thanks for mentioning it - I haven&#039;t seen that package for some reason. I&#039;m a bit surprised they took the long road and parsed &lt;code&gt;var_dump&lt;/code&gt;&#039;s output, when a serialized string is so much easier to parse.

@Josh Johnston
I probably should have mentioned explicitly, but this class just generates an array structure, which describes the variable. This can subsequently be transformed into html or any other kind of output. I left that part out though, since it&#039;s rather trivial. One use case could be to json-encode the structure and send it to the Firebug console. Try the following, to see what I mean:

&lt;pre&gt;&lt;code class=&#039;php&#039;&gt;$x = new XrayVision();
print_r($x-&gt;export($x));
&lt;/code&gt;&lt;/pre&gt;

Which will give you:

&lt;pre&gt;&lt;code class=&#039;php&#039;&gt;Array
(
    [type] =&gt; object
    [id] =&gt; 1
    [class] =&gt; XrayVision
    [value] =&gt; Array
        (
            [protected:id] =&gt; Array
                (
                    [type] =&gt; integer
                    [id] =&gt; 2
                    [value] =&gt; 1
                )

        )

)
&lt;/code&gt;&lt;/pre&gt;

@Nick
Burden of proof? I didn&#039;t know I was on trial.

@Tarh
Thanks, though I don&#039;t think it&#039;s fair to judge the entire PHP community on the grounds of one raging madman.</description>
		<content:encoded><![CDATA[<p>@Ken Guest<br />
Thanks for mentioning it &#8211; I haven&#8217;t seen that package for some reason. I&#8217;m a bit surprised they took the long road and parsed <code>var_dump</code>&#8217;s output, when a serialized string is so much easier to parse.</p>
<p>@Josh Johnston<br />
I probably should have mentioned explicitly, but this class just generates an array structure, which describes the variable. This can subsequently be transformed into html or any other kind of output. I left that part out though, since it&#8217;s rather trivial. One use case could be to json-encode the structure and send it to the Firebug console. Try the following, to see what I mean:</p>
<pre><code class='php'>$x = new XrayVision();
print_r($x-&gt;export($x));
</code></pre>
<p>Which will give you:</p>
<pre><code class='php'>Array
(
    [type] =&gt; object
    [id] =&gt; 1
    [class] =&gt; XrayVision
    [value] =&gt; Array
        (
            [protected:id] =&gt; Array
                (
                    [type] =&gt; integer
                    [id] =&gt; 2
                    [value] =&gt; 1
                )

        )

)
</code></pre>
<p>@Nick<br />
Burden of proof? I didn&#8217;t know I was on trial.</p>
<p>@Tarh<br />
Thanks, though I don&#8217;t think it&#8217;s fair to judge the entire PHP community on the grounds of one raging madman.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Nick</title>
		<link>http://www.sitepoint.com/blogs/2008/11/11/how-to-expose-phps-private-parts/comment-page-1/#comment-825346</link>
		<dc:creator>Nick</dc:creator>
		<pubDate>Wed, 12 Nov 2008 22:06:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=3169#comment-825346</guid>
		<description>I definitely do not mean any personal offense to the author.  But the article is misleading, confusingly written, the code example inadequate to address the issues raised as the article&#039;s thesis, the example solves a non-existant problem in a very inefficient manner, and there are some factual errors.</description>
		<content:encoded><![CDATA[<p>I definitely do not mean any personal offense to the author.  But the article is misleading, confusingly written, the code example inadequate to address the issues raised as the article&#8217;s thesis, the example solves a non-existant problem in a very inefficient manner, and there are some factual errors.</p>]]></content:encoded>
	</item>
</channel>
</rss>
