-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix Bug #77226: convert object which has invisible properties to array. #3696
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There's a lot of code relying on the current behavior, I doubt we can change it. It's possible to use |
...include output 0x00 in PHP script? I think this is terrible... Is this a feature? |
@twose Object to array casts are a very fast and reliable way to access all the properties of an object. This is necessary for many libraries that do things like serialization, dumping, comparison, etc. I definitely think that having this as a default behavior for array casts is bad, but it's not something we can simplify change at this point in time. A good starting point may be to add a new function which provides the current functionality of object-to-array casts under a more explicit name and with less edge cases (e.g. ArrayObject is one of the big offenders, where you need to set a special flag to get normal array-to-object behavior). Libraries that need this functionality can then migrate to that function. @Ocramius might be a good person to talk to about this. |
This is indeed normal/expected. The |
Thank you for your explanation, never thought that... 😧 |
@Ocramius What do you think about
|
I talked about it with @jpauli while at Web5 in 2013: ideally, I'd love to have an API like the one of |
You could probably put such an API in:
Bad idea? Absolutely, but it is not meant for OOP, and rather for serialisation purposes. |
What about __set_state() ? Cannot it help doing what you need ? |
For tools like JMSSerializer, Doctrine ORM, zendframework/zend-di, zendframework/zend-servicemanager, php-di/php-di, ocramius/proxy-manager, phpunit and so on, this would be quite the massive speed-up. For everyone else: not to be used, as it's gonna be something quite dangerous :-) |
Ok I see, we could add facilities to Reflection, that wouldn't be hard to program. |
Feasible, can probably help during the holidays. Should we take this offline, in private convo? |
Yes Ok you can fetch me by email or on IRC :-) |
all PHP versions and systems
script
output
when we convert object which has invisible properties to array, it uses the zend_mangle_property_name result.
I think we can do what the
json_encode
does, skip protected and private members.