> Inspired by the recent discussion on __toArray(), I'd like to propose the
> addition of a get_mangled_object_properties() function, implemented in
> https://github.com/php/php-src/pull/4163.
> 
> This function returns the mangled object properties (duh...), which matches
> the behavior of the (array) cast, with the difference that an overloaded
> (array) cast will be ignored. To the best of my knowledge the only internal
> class currently doing this is ArrayObject.
> 
> There are a couple of motivation for this:
> 1. It makes it more obvious that code operates on mangled properties. This
> allows clearly distinguishing (array) casts used for low-level object
> introspection and (array) casts used for things like converting between
> stdClass and arrays.
> 2. It is more robust, because it is not affected by overloading. At least
> in theory it allows us to introduce the __toArray() method proposed in the
> other thread (though I don't personally endorse this).
> 3. Longer term, it would allow us to change (array) to return non-mangled
> (visibility-respecting) properties -- the current behavior is a WTF factor
> for anyone who doesn't happen to work on serialization or dumping libraries.
> 
> Thoughts?
> 
> Regards,
> Nikita

I think this is a great idea. Not just because I want __toArray() to succeed, 
but because some of the concerns raised by its discussions were mainly focused 
on the odd behavior that current array casting exhibits and possibly losing 
that. By introducing this new function, it can be a more appropriate method of 
gaining insight into a class' properties.

I like the idea of renaming the function to "get_mangled_object_vars()" that 
was mentioned on the PR. It does bring it more in line with current naming 
schemes.

--
Steven Wade
stevenwad...@gmail.com




--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to