Re: dump a class

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 2007-11-29 at 18:16 +0100, Alex Toro wrote:
> Hello, I would like to know why when I print_r or var_dump an object I
> get the private properties. I give you an example:
> 
> <?php
> 
> class test
> {
> 	private $myPrivate = 'topsecret';
> }
> 
> $myTest = new test();
> 
> #echo $myTest->myPrivate; // Fatal error: Cannot access private property
> test::$myPrivate in ..... that's OK!
> 
> echo '<pre>';
> print_r($myTest);
> #test Object
> #(
> #    [myPrivate:private] => topsecret
> #)
> var_dump($myTest);
> #object(test)#1 (1) {
> #  ["myPrivate:private"]=>
> #  string(9) "topsecret"
> #}
> echo '</pre>';
> 
> ?>
> 
> A private member is suposed to be private, isn't it?

It's private in the context of runtime requests to retrieve or set the
value via the normal methods for setting and retrieving data properties.
Most people use print_r() and var_dump() to debug their data structures,
in which case they certainly do want to see the private members. Even if
they were hidden you would find it to be absolutely necessary that they
be exposed when serialized, otherwise how could you properly
unserialize. Given that condition, does it matter that they are visible
via print_r() or var_dump() when another method for viewing them exists?

Cheers,
Rob.
-- 
...........................................................
SwarmBuy.com - http://www.swarmbuy.com

    Leveraging the buying power of the masses!
...........................................................

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux