Re: [PHP4BETA] Object property collection?
| From: | Andrei Zmievski | Date: | Mon, 01 May 2000 13:32:00 +0000 |
| Subject: | Re: [PHP4BETA] Object property collection? | ||
| References: | 1 | Groups: | php.version4 |
| Request: | Send a blank email to php-version4+get-14267@lists.php.net to get a copy of this message | ||
On Mon, 01 May 2000, Seth Banks wrote:
> Hey all,
>
> I know this might not be the right list, but then again it might be....
>
> In php4 is there any way to access an object's properties via a collection
> or array? So you could do something like this:
>
> class blah {
> var $one;
> var $two;
> var $three;
> ...
> for ($i=0; $this->properties->length > $i; $i++) {
>
> }
> }
>
>
> Is that possible? Thanks!
There are two functions that do this: get_class_vars() and
get_object_vars(). The first one takes a class name and returns an array
of property names that were defined inside the class with "var..". The
second one takes an instantiated object and returns an array of property
names that object has - which may be more than were defined for the
class.
-Andrei
* Programming is an art form that fights back. *