A few days ago, I posted about some interesting behavior when casting arrays to objects. I would like to take a look at some other interesting behavior. Lets start be creating a basic class Test with three properties each with a different visibility.
Now create a new instance of the class and cast it to an array.
The result is as follows:
On the surface it appears as if the private property had the class name prepended and the and the protected property had an astrick prepended. Now what happens if we cast this array back to an object?
How did PHP know the Testfoo key and the *bar key were private and protected? After all, doing the following does not work:
It turns out, PHP stores meta information with the keys in the form of null bytes. Thus