Re: Printing a PHP Class
| From: | Markas | Date: | Thu, 01 Aug 2002 08:49:52 +0000 |
| Subject: | Re: Printing a PHP Class | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-110644@lists.php.net to get a copy of this message | ||
Its hard to imagine anything better and clear than what print_r() or even
var_dump() outputs...
"Marty McGowan" <marty3@mcgowans.org> wrote in message
news:1103_1028146508@news.php.net...
> PHPers,
> In a genaology application, where I add individuals to
> an array:
>
> $everyone[] = new Individual($id);
>
> I'd like to print the indiviuals' attributes. Some of these are
> in array's themselves: like a list of event's in one's life.
>
> My problem is:
> when printing the Class Variables using the "standard" approach:
> =========
> function print_vars($obj) {
> $arr = get_object_vars($obj);
> while (list($prop, $val) = each($arr))
> {
> echo "$prop\t$val\n";
> }
> }
> =========
> I see the message:
>
> Variables: Person: Added RELI attribute
>
> id I6
> last McGOWAN
> first Martin James
> suffix Sr.
>
> sex M
>
> lifeevent Array
> attribute Array
> ========
>
> My question is:
> How does one print out the "Array"?
>
> My attempt at testing .
>
> (strcmp($val,"Array") == 0)
>
> was fruitless, as the print value of
> $var is always a string, but not always
> in other contexts.
>
> What am I missing?
>
> Thanks,
> -- Marty McGowan
>
>
>