Re: Object to array conversion oddity

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, September 23, 2006 10:39 am, Marcus Bointon wrote:
> On 23 Sep 2006, at 16:37, Ray Hauge wrote:
>
>> Could you do something like this?
>>
>> $private = "Myclass"
>> $protected = "*";
>
> No, because if I have a property called 'Myclassfield1', after
> casting to an array I can't tell if it's private property called
> 'field1' or a public property called 'Myclassfield1'.

Don't do that. :-)

> I think it's just plain wrong. Arrays should not try to be objects.
> You can find out protection level of a property via introspection of
> the object that you have in hand. In the vast majority of cases,
> you'll want it to act just like the docs say it does, and if you
> don't, you should probably be using the object itself anyway.

Perhaps it would also be accurate to say that Objects should not try
to be Arrays? :-)

Seriously.

I mean, the type coercion object->array made sense in PHP3 and even
PHP4 where an Object was not much more than a glorified struct, or an
array with some extra baggage.

You start using that PHP5 private/protected stuff, and it just doesn't
make sense to coerce it to an array, imho.

YMMV

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux