Re: get_object_vars ($this) and member visibility [message #169391] |
Thu, 09 September 2010 07:34 |
Helmut Chang
Messages: 22 Registered: September 2010
Karma:
|
Junior Member |
|
|
Jerry Stuckle schrieb:
>> I want to use collection objects, where I have methods but where I also
>> can iterate over the elements in the collection and where I can access
>> elements in the collection in an array-/[]-style. And where I can
>> restrict the type of elements that are allowed in the collection.
>>
>
> Which is completely different than mapping the properties to array
> elements.
Yes, it is. I wrote this also in my previous post :). I wrote "too
simplified", because I wanted to show cases, where it might be useful to
have an object, that behaves like an array. Your posting, I replied to,
suggests IMHO, you think the whole ArrayAccess, Iterator, etc. intefaces
are useless.
> But unfortunately, PHP doesn't support either restricting the
> type in the collection or overloading operators.
I'm just trying to implement collection classes that restrict the type
of their elements. It's not 100% perfect, as PHP itself gives you the
retrictions, but:
Because of this thread, I tested the ArrayAccess interface once again
with PHP 5.3 and finally it "works as expected". Which means, if you
implement it and pass an object in the offsetSet() method, it is a
reference now. IIRC, until 5.3, it was a copy, which made this interface
pretty useless.
And the offsetSet() method of the interface gives you also the
possibility to throw an exception, if the provided value is not of the
correct type. But yes: unfortunately you cannot define this in the
methods signature.
Helmut
--- news://freenews.netfront.net/ - complaints: news(at)netfront(dot)net ---
|
|
|