Skip to content

Introduce ReflectionProperty::getMangledName() #18605

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

Open
mvorisek opened this issue May 20, 2025 · 7 comments
Open

Introduce ReflectionProperty::getMangledName() #18605

mvorisek opened this issue May 20, 2025 · 7 comments

Comments

@mvorisek
Copy link
Contributor

Description

repro: https://3v4l.org/2pnIb

Because the properties are renamed.

@mvorisek mvorisek changed the title Emit a warning when "array with private/protected keys" is casted to an object Emit a warning when array "with private/protected keys" is casted to an object May 20, 2025
@iluuu1994
Copy link
Member

This follows the normal mangling scheme for properties. Emitting a warning is not useful, because you can't really prevent it, and the code is not wrong. You need to change the way you access protected properties in an array created from an object to array cast.

@iluuu1994
Copy link
Member

I'm assuming this is related to the suggestion in #18600 (comment). One thing that would be possible is providing something like ReflectionProperty::getMangledName(). Would that help? I agree that having to handle mangling yourself is not great.

@mvorisek
Copy link
Contributor Author

ReflectionProperty::getMangledName() would be nice.

@nielsdos nielsdos changed the title Emit a warning when array "with private/protected keys" is casted to an object Introduce ReflectionProperty::getMangledName() May 20, 2025
@nielsdos
Copy link
Member

I agree. I retargeted the issue therefore to the introduction of such a method.

@mvorisek
Copy link
Contributor Author

mvorisek commented May 20, 2025

This issue is about renamed keys when casting array to object/stdClass. (3rd and 4th dump in [repro])

-> here I would not speak about any "mangling"

The ReflectionProperty::getMangledName() is about casting any object to array. (2nd dump in [repro])

-> here the result follow the property mangled names

[repro] https://3v4l.org/2pnIb

@iluuu1994
Copy link
Member

There is no issue in your code. Property mangling is a feature that prevents naming collisions between properties with different visibilities. You need to use the mangled name when accessing values our of the properties hash table. This behavior is decades old (PHP 5.0).

@mvorisek
Copy link
Contributor Author

(I have update my post above what I consider "mangling" and what not)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants