# [RFC] Static variables in inherited methods

- Thread: https://externals.io/message/113594
- Original archive: https://news-web.php.net/php.internals/113594
- Started by drealecs@gmail.com on 2021-03-17T18:56:20+00:00
- Messages: 4
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #113591 — Nikita Popov — 2021-03-17T15:29:50+00:00

URL: https://externals.io/message/113594#113591

> Hi internals,
>
> While looking into various issues related to static variable handling,
> I've become increasingly convinced that our handling of static variables in
> inherited methods is outright buggy. However, it's also long-standing
> behavior, so I've put up an RFC:
>
> https://wiki.php.net/rfc/static_variable_inheritance
>

I have now created an implementation for this change, and updated the RFC
with some sample code for how one can preserve the old behavior, if it's
being used deliberately. I plan to move forward with voting soon.

Regards,
Nikita

---

## #113592 — drealecs@gmail.com — 2021-03-17T16:48:29+00:00

URL: https://externals.io/message/113594#113592 · In reply to: #113591

> 
>
> > […]
> in
> > […]
>
> I have now created an implementation for this change, and updated the RFC
> with some sample code for how one can preserve the old behavior, if it's
> being used deliberately. I plan to move forward with voting soon.
>

Maybe it would be good to have links to some bug reports (that you
mentioned) or a code snippet like this https://3v4l.org/J8Mme
to clearly show that copying the static variable happens on inheritance
point, with whatever that variable was at that point
so it would be clear that the current behavior is undefined considering
only B class, if it would be to ignore what happened to A in the meantime.

Thanks,
Alex

---

## #113593 — Nikita Popov — 2021-03-17T17:05:38+00:00

URL: https://externals.io/message/113594#113593 · In reply to: #113592

On Wed, Mar 17, 2021 at 5:48 PM Alexandru Pătrănescu <drealecs@gmail.com>
wrote:

>
> 
>
> > […]
>
> Maybe it would be good to have links to some bug reports (that you
> mentioned) or a code snippet like this https://3v4l.org/J8Mme
> to clearly show that copying the static variable happens on inheritance
> point, with whatever that variable was at that point
> so it would be clear that the current behavior is undefined considering
> only B class, if it would be to ignore what happened to A in the meantime.
>
> Thanks,
> Alex
>

We already changed that behavior for PHP 8.1 independently of this RFC --
static variables will no longer depend on point of inheritance. This RFC is
in addition to that change (and subsumes it really, because point of
inheritance cannot matter anymore.)

Regards,
Nikita

---

## #113594 — drealecs@gmail.com — 2021-03-17T18:56:20+00:00

URL: https://externals.io/message/113594#113594 · In reply to: #113593

> On Wed, Mar 17, 2021 at 5:48 PM Alexandru Pătrănescu <drealecs@gmail.com>
> wrote:
>
> > […]
>
> We already changed that behavior for PHP 8.1 independently of this RFC --
> static variables will no longer depend on point of inheritance. This RFC is
> in addition to that change (and subsumes it really, because point of
> inheritance cannot matter anymore.)
>
> Regards,
> Nikita
>

Right, thanks for explaining. I remembered I saw it on mentioned somewhere
but didn't know exactly where.
Searched it now and it was this PR: https://github.com/php/php-src/pull/6705

Thank you,
Alex
