(on Monday, 23 February 2009, 10:43 PM +0100):
> Matthew Weier O'Phinney wrote:
> > -- Piotr Kabaciński <kabot@seo.pl> wrote
> > (on Sunday, 22 February 2009, 09:51 PM +0100):
> > > I wonder why all attributes are kept like common object attribute and
> > > why methods like get/setAttrib operate on $this->$name.
> > >
> > > Wasn't it faster if there is array eg. $this->attributes and every
> > > operation on attribute will be simple get $this->attributes[$name]?
> >
> > You're forgetting that get/setAttrib() are not the only way to affect
> > these attributes: the primary API is to use overloading.
> >
> > The solution you present may be faster when you want to get at all
> > attributes at once (a micro-optimization at best), but not when you want
> > to retrieve a single attribute -- if you use overloading, it will
> > actually be faster, as you'll be grabbing a public property.
>
> Ok, i must say i am little bit convinced. But i still think it is not
> very elegant to retrive all parameters and then unset these which are
> not start with '_'. Would be nice if i could list all of it without any
> additional action.
Unfortunately, get_object_vars() returns all properties, not just public
ones. PHP limitation.
We could potentially use the Reflection API, but that's significantly
more expensive than get_object_vars() (even when you need to loop over
the results).
--
Matthew Weier O'Phinney
Software Architect | matthew@zend.com
Zend Framework | http://framework.zend.com/
没有评论:
发表评论