# static:: and PHP 7 (from bug #70997)

- Thread: https://externals.io/message/89490
- Original archive: https://news-web.php.net/php.internals/89490
- Started by Peter Cowburn on 2015-11-30T12:16:45+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

---

## #89490 — Peter Cowburn — 2015-11-30T12:16:45+00:00

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

Hi internals,

I'm looking for some feedback on a change with regard to static::, which
has been present throughout the 7 branch.

Have a look-see at https://bugs.php.net/bug.php?id=70997

<?php

class A {
    const TEST = false;
    public function test() {
        var_dump(static::TEST);
    }
}

class B extends A {
    const TEST = true;

    public function test() {
        A::test();
    }
}

$b = new B;
$b->test();

?>

In PHP 7 it dumps true, in PHP 5 false.

I'm looking for info on when, where, why it was introduced, and ultimately
some clarification of:
a) was this intentional
b) it is going to stay (i.e. "not a bug")
c) some more to go on so I can document the change clearly

If there is already a line in NEWS/UPGRADING or a commit you can point me
to, that would be amazing.

Whatever tangents this topic wanders off on, I'd like to eventually pull it
back to the bug report mentioned above with one eye on formulating the docs
changes (if it's really "not a bug").

Cheers,

A docs guy.

---

## #89491 — Peter Cowburn — 2015-11-30T12:18:11+00:00

URL: https://externals.io/message/89490#89491 · In reply to: #89490

> Hi internals,
>
> I'm looking for some feedback on a change with regard to static::, which
> has been present throughout the 7 branch.
>
> Have a look-see at https://bugs.php.net/bug.php?id=70997
>
> <?php
>
> class A {
>     const TEST = false;
>     public function test() {
>         var_dump(static::TEST);
>     }
> }
>
> class B extends A {
>     const TEST = true;
>
>     public function test() {
>         A::test();
>     }
> }
>
> $b = new B;
> $b->test();
>
> ?>
>
> In PHP 7 it dumps true, in PHP 5 false.
>

Gah, this was inevitable!  In PHP 7 it dumps FALSE, in PHP 5 TRUE. Stupid
brain.


>
> I'm looking for info on when, where, why it was introduced, and ultimately
> some clarification of:
> a) was this intentional
> b) it is going to stay (i.e. "not a bug")
> c) some more to go on so I can document the change clearly
>
> If there is already a line in NEWS/UPGRADING or a commit you can point me
> to, that would be amazing.
>
> Whatever tangents this topic wanders off on, I'd like to eventually pull
> it back to the bug report mentioned above with one eye on formulating the
> docs changes (if it's really "not a bug").
>
> Cheers,
>
> A docs guy.

---

## #89492 — Andreas Heigl — 2015-11-30T12:23:51+00:00

URL: https://externals.io/message/89490#89492 · In reply to: #89491

Am 30.11.15 um 13:18 schrieb Peter Cowburn:
> class A {
> > […]
You are calling explicitly A::test().

When you call parent::test() everything works as you'd expect it.

Have a look at https://3v4l.org/RCrRd

Apart from that you are calling an instance-method as a static method by
using A::test().

Cheers

Andreas

-- 
                                                              ,,,
                                                             (o o)
+---------------------------------------------------------ooO-(_)-Ooo-+
| Andreas Heigl                                                       |
| mailto:andreas@heigl.org                  N 50°22'59.5" E 08°23'58" |
| http://andreas.heigl.org                       http://hei.gl/wiFKy7 |
+---------------------------------------------------------------------+
| http://hei.gl/root-ca                                               |
+---------------------------------------------------------------------+

---

## #89493 — Bob Weinand — 2015-11-30T12:47:26+00:00

URL: https://externals.io/message/89490#89493 · In reply to: #89492

> Am 30.11.2015 um 13:23 schrieb Andreas Heigl <andreas@heigl.org>:
> 
> Am 30.11.15 um 13:18 schrieb Peter Cowburn:
> > […]
> You are calling explicitly A::test().
> 
> When you call parent::test() everything works as you'd expect it.
> 
> Have a look at https://3v4l.org/RCrRd
> 
> Apart from that you are calling an instance-method as a static method by
> using A::test().
> 
> Cheers
> 
> Andreas

We do that, because we may not have any other choice, e.g. when calling a great-parents method. To then use LSB, we have to explicitly name our parent.
This is now not possible anymore, and hence I’d consider this as a BC break at least, if not a bug.

This definitely is not simply *not a bug*.

Bob

---

## #89499 — Rowan Collins — 2015-11-30T14:48:59+00:00

URL: https://externals.io/message/89490#89499 · In reply to: #89492

Andreas Heigl wrote on 30/11/2015 12:23:
> Am 30.11.15 um 13:18 schrieb Peter Cowburn:
> > […]
> You are calling explicitly A::test().
>
> When you call parent::test() everything works as you'd expect it.
>
> Have a look at https://3v4l.org/RCrRd
>
> Apart from that you are calling an instance-method as a static method by
> using A::test().

This appears to be the crucial thing: if you declare the test() method 
as static in both classes, it returns false in all versions: 
https://3v4l.org/hJoor

It's almost like A::test() is now interpreted as a static call, rather 
than a "scope resolution" of the instance method, but $this is still 
available, so it's not quite as simple as that: https://3v4l.org/qbT3j

Regards,
-- 
Rowan Collins
[IMSoP]

---

## #89500 — Xinchen Hui — 2015-11-30T15:07:40+00:00

URL: https://externals.io/message/89490#89500 · In reply to: #89499

Hey：

> 
> 
> Andreas Heigl wrote on 30/11/2015 12:23:
> > […]
> 
> This appears to be the crucial thing: if you declare the test() method as static in both classes, it returns false in all versions: https://3v4l.org/hJoor
> 
> It's almost like A::test() is now interpreted as a static call, rather than a "scope resolution" of the instance method, but $this is still available, so it's not quite as simple as that: https://3v4l.org/qbT3j
> 
dmitry has committed a fix, please have a look

Thanks
> Regards,
> -- 
> Rowan Collins
> [IMSoP]
