Re: How can I get a list of object vars?

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

 



i think you misunderstood me; i was recommending you NOT use the array cast
of an object to accomplish your task.
rather, i would advise you spend time learning the reflection API because
its designed for retrieval of information about
classes and functions, etc..
apparently the array cast method does show you the public members of the
class.  it does not accurately show the private
members though.  if you look at the output of what you sent, you will see
the name of the object, Obj, i prepended to the
name of the private data members.
there are other drawbacks to simply casting the object as an array and
trying to iterate over the array contents.  some of
these are,
 - you loose the ability to determine the access specifier of the current
member
 - you cannot analyze class methods

i dont know what exactly youre trying to do, but xml may not be a bad
choice, you should weigh the work it will take to
understand and utilize the reflection api against it after you experiment w/
the reflection api more.

-nathan

On 8/2/07, js <ebgssth@xxxxxxxxx> wrote:
>
> Thank you, it worked, but it contains some dust.
> Is it possible to remove  the  dust?
>
> <?php
> class Obj {
> private $priv;
> public $pub;
> protected $prot = 'foo';
> }
> $obj = new Obj();
> $obj->more_var = 'val';
>
> foreach ((array)$obj as $k => $v)
>   echo "$k = $v\n";
> ?>
>

[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