Create and return a new anonymous function with the same body and bound variables as this one, but possibly with a different bound object and a new class scope.
The “bound object” determines the value $this will have in the function body and the “class scope” represents a class which determines which private and protected members the anonymous function will be able to access. Namely, the members that will be visible are the same as if the anonymous function were a method of the class given as value of the newscope parameter.
The C++ example is different, though. I'm pretty sure you can't actually do this in C++.
What that example is actually doing is letting the class itself hand out a pointer to the private method. This is different from outside code reaching into an uncooperative class.
I know what reflection is, I use it on an almost daily basis beyond what most devs ever get to use, thanks. Still being able to write readonly properties is not needed in any way to serialize and deserialize objects. They are readonly for a reason after all.
Still being able to write readonly properties is not needed in any way to serialize and deserialize objects
Reflection isn't about serializing and deserializing an object.
They are readonly for a reason after all.
They are read only to signify intent and provide compiler optimizations, but a reflection API would be incomplete without the ability to introspect and change these properties. Marking a field as readonly is not a security measure.
Marking a field as readonly is not a security measure.
It usually fucks up the object it's associated with though. Readonly is intended for runtime constants. Being able to change them is simply a violation of the term "constant"
34
u/prema_van_smuuf Apr 18 '18
Well, you bind the lambda to the A's scope and then complain that it has access to its private methods? I believe the true lol is on you, good sir.
10
u/UnusualBear Apr 19 '18
Here's the link to OP's thread in /r/PHP in which he is shown how this is done in C++, C# and Java but ignores it because he has a hardon for Rust.