Re: [RFC] Pass Scope to Magic Accessors

From: Date: Mon, 23 Jan 2023 16:26:40 +0000
Subject: Re: [RFC] Pass Scope to Magic Accessors
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-119399@lists.php.net to get a copy of this message
> 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? > Yep. That's already the case: using a rebound close, we can fake any scope already so this is not new capability. > 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. > Legit concerns. I'm going to prepare a more extensive use case so the motivations of RFC become more obvious. I'll get back on this thread when ready. Stay tuned :) Nicolas

« previous php.internals (#119399) next »