Hi
On 1/19/23 18:43, Ilija Tovilo wrote:
> You're right, we'll try to improve the wording and provide a handful of
> examples. Essentially, $callingScope should contain the class name of
> the calling scope, so the place where the magic method was called. When
> the calling scope is not a class (global scope, function, static
> closure, etc.) null is passed instead.
Thank you, this is more clear now.
> given property. This is not a problem when the property is supposed to
> be public but becomes difficult when trying to restrict access to it. It
If I understand the proposal correctly, then any access restriction
would effectively be a Gentleman's agreement only, because nothing is
preventing me from calling '$someObj->__get('someProp',
$someObj::class);', no?
Honestly so far I fail to see the cost/benefit ratio to be acceptable
for the added complexity here. Not just the implementation complexity
within the language itself, but also because this will need to be
documented within the PHP manual and integrated within tooling, such as
static analyzers.
Is there some real-world example where I would employ this type of
access control within the magic methods and where "not documenting the
property to not expose it to the IDE autocompletion" would not be
sufficient, but this easily circumventable check would be?
My only use case of __get() so far was making properties visible to the
public, while restricting write access, so this is not a problem I
needed to solve before.
Best regards
Tim Düsterhus