# [RFC] Pass Scope to Magic Accessors

- Thread: https://externals.io/message/119350
- Original archive: https://news-web.php.net/php.internals/119350
- Started by Nicolas Grekas on 2023-01-19T16:23:38+00:00
- Messages: 6
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #119350 — Nicolas Grekas — 2023-01-19T16:23:38+00:00

URL: https://externals.io/message/119350#119350

Hi internals,

Ilija and I would like to start a discussion about the following RFC:
https://wiki.php.net/rfc/pass_scope_to_magic_accessors

When using magic methods to access actual properties, respecting their
declared visibility is often desired. Yet, accessing the calling scope to
emulate the visibility restrictions is unreasonably difficult at the
moment. This RFC proposes to pass the calling scope to magic accessors to
make it trivial to get it.

Kind regards,
Nicolas

---

## #119351 — tim@bastelstu.be — 2023-01-19T16:29:28+00:00

URL: https://externals.io/message/119350#119351 · In reply to: #119350

Hi


> Ilija and I would like to start a discussion about the following RFC:
> https://wiki.php.net/rfc/pass_scope_to_magic_accessors
> 
> When using magic methods to access actual properties, respecting their
> declared visibility is often desired. Yet, accessing the calling scope to
> emulate the visibility restrictions is unreasonably difficult at the
> moment. This RFC proposes to pass the calling scope to magic accessors to
> make it trivial to get it.
> 

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

---

## #119353 — Aleksander Machniak — 2023-01-19T18:23:19+00:00

URL: https://externals.io/message/119350#119353 · In reply to: #119350

> Hi internals,
> 
> Ilija and I would like to start a discussion about the following RFC:
> https://wiki.php.net/rfc/pass_scope_to_magic_accessors
> 
> When using magic methods to access actual properties, respecting their
> declared visibility is often desired. Yet, accessing the calling scope to
> emulate the visibility restrictions is unreasonably difficult at the
> moment. This RFC proposes to pass the calling scope to magic accessors to
> make it trivial to get it.

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
Kolab Groupware Developer        [https://kolab.org]
Roundcube Webmail Developer  [https://roundcube.net]
----------------------------------------------------
PGP: 19359DC1 # Blog: https://kolabian.wordpress.com

---

## #119354 — Marco Pivetta — 2023-01-19T18:40:04+00:00

URL: https://externals.io/message/119350#119354 · In reply to: #119353

Not just that, but `debug_backtrace()` already exists for that purpose.



> 
> > […]
>
> 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
> Kolab Groupware Developer        [https://kolab.org]
> Roundcube Webmail Developer  [https://roundcube.net]
> ----------------------------------------------------
> PGP: 19359DC1 # Blog: https://kolabian.wordpress.com
>
> --
> 
> To unsubscribe, visit: https://www.php.net/unsub.php

---

## #119419 — Clint Priest — 2023-01-24T15:51:14+00:00

URL: https://externals.io/message/119350#119419 · In reply to: #119354

> Not just that, but `debug_backtrace()` already exists for that purpose.
>
I have use `debug_backtrace()` exactly for this purpose in the past. It 
was to make a protected property readable/writable, but only by certain 
"friend classes."

It's pretty trivial to make happen with `debug_backtrace()` and even more 
so if you wrap it in its own reusable function.

I don't see the need to implement this in the language since it's 
possible to achieve in userland trivially.

---

## #121761 — Nicolas Grekas — 2023-11-22T18:30:17+00:00

URL: https://externals.io/message/119350#121761 · In reply to: #119350

Hi all,

Ilija and I would like to start a discussion about the following RFC:
> https://wiki.php.net/rfc/pass_scope_to_magic_accessors
>
> When using magic methods to access actual properties, respecting their
> declared visibility is often desired. Yet, accessing the calling scope to
> emulate the visibility restrictions is unreasonably difficult at the
> moment. This RFC proposes to pass the calling scope to magic accessors to
> make it trivial to get it.
>

Just a quick heads up on this thread to let you know that I'm withdrawing
the RFC.
I'm working with Arnaud Le Blanc on a native implementation of lazy objects
and I don't need fast access to the calling scope for any other use case.
If anyone has, feel free to follow up, but on my side I'm going to focus on
that new soon-to-be RFC for lazy objects. Stay tuned :)

Even if I'm withdrawing, I'm sending a Big Thank You to Ilija for writing
the prototype implementation.
Also thank you to everybody who took some time to review the proposal!

Cheers,
Nicolas
