Re: [PHP4BETA] Session: objects containing objects
| From: | Ulf Wendel | Date: | Thu, 24 Feb 2000 21:05:49 +0000 |
| Subject: | Re: [PHP4BETA] Session: objects containing objects | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.version4 |
| Request: | Send a blank email to php-version4+get-10896@lists.php.net to get a copy of this message | ||
Boris Erdmann wrote:
>
> Ulf Wendel wrote:
> >
> > Andrei Zmievski wrote:
> > >
> > > On Thu, 24 Feb 2000, Ulf Wendel wrote:
> > > > get_member_vars() sounds good, although I prefer slots or fields.
> > > Ok, just a little more thinking. Do you really need a function? Can't
> > > you use foreach() or each() to iterate over them?
> >
> > Yes, I can. But as far as I know this feature is not documented
> > and more important will PHP5 beahave the same way?
> >
> > I would like to see
> > php to break with hacks. It's not very common that you can tread
> > an object like an array. An object is completely different from
> > an array, isn't it?
> >
> Well, this is questionable. Semantically they are different. But
> they are often implemented in similar ways. Another popular example
> is JavaScript where you cant really draw a line between arrays and
> objects since arrays are alway methodless objects. Thus you have both
> notations for accessing array and objects. there is no difference
> between
>
> object.slot
> object["slot"]
> array["key"]
> array.key
>
> This leads to another question: why cant we make this possible in php?
This is a really good question. All I'm looking for is to eliminate
breaks in the logics of php. It's not very logical, that you can tread
an object like an array to get it's slots but you have to call
get_class() to get it's instance name...
I can live with the way Boris sketched. BUT I want php to take exactly
one way. Eighter an object can be used like an array:
$obj = new foo;
echo $obj["slot1"];
echo $obj["_CLASSNAME"] ( => obj )
echo $obj["_PARENT"] ( => NULL)
echo $obj["_CHILDREN"] ( => NULL)
or it behaves like a black box:
$obj = new foo;
echo get_class($obj) ( => obj )
echo get_parent_class($obj) ( => NULL )
echo get_child_class($obj) ( => NULL)
echo get_class_vars($obj) ( => Array ( name => value ) )
You have started with get_class(), why not follow that way?
Ulf