Re: [RFC] Pass Scope to Magic Accessors

From: Date: Thu, 19 Jan 2023 19:25:55 +0000
Subject: Re: [RFC] Pass Scope to Magic Accessors
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-119355@lists.php.net to get a copy of this message
Hi Aleksander >> https://wiki.php.net/rfc/pass_scope_to_magic_accessors > > Why not a new function, e.g. func_call_scope()? It could work > everywhere, not only in magic methods. > > I guess it would be tricky with calls to the parent magic method when > you need the "outer calling scope", but I'd like to see some reasoning > in the RFC. > > -- > Aleksander Machniak This has been suggested before and we're consider it. Here's a comparable PHP implementation. https://3v4l.org/6Ua8t This would only work when called directly from the magic method but that seems appropriate given that you'd also have to pass $callingScope to any function requiring it. Nicolas has noted that this would make it impossible to pass something other than the actual calling scope to parent::__get(). It's not clear yet whether there's a use case for that. --- Hi Marco > Not just that, but debug_backtrace() already exists for that > purpose. As mentioned in the RFC and the last e-mail, yes this can be achieved via debug_backtrace(). However, as demonstrated by the 3v4l, it's not exactly trivial. It also requires the full stack trace, as well as all frame objects and arguments. That's not going to be great for performance. So saying debug_backtrace() exists for this purpose is misleading, to say the least. Ilija

« previous php.internals (#119355) next »