Hi Tim >> Ilija and I would like to start a discussion about the following RFC: >> https://wiki.php.net/rfc/pass_scope_to_magic_accessors > > Unless I missed anything, the RFC does not explain how the values that > are passed into the second parameter will look like. What kinds of > strings will be passed? When will the value be null? > > Best regards > Tim Düsterhus
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. https://gist.github.com/iluuu1994/c7950245c13c21f559c81776100b09e0 This is essentially trying to provide a way to implement visibility checks for magic methods. Magic methods will be called from any scope, so it is hard to tell whether the calling scope is allowed to access the 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 is possible through debug_backtrace() (as Nicolas demonstrates in the RFC) but it's not very robust and becomes more complex when trying to cover all cases (e.g. calls to parent::__get()). The proposal aims to simplify this use case. We'll try to clarify this in the RFC in the coming days. Thanks for the feedback! Ilija -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: https://www.php.net/unsub.php
