# behaviour of static calls to regular methods

- Thread: https://externals.io/message/10676
- Original archive: https://news-web.php.net/php.internals/10676
- Started by Ard Biesheuvel on 2004-06-21T12:54:02+00:00
- Messages: 3
- 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

---

## #10676 — Ard Biesheuvel — 2004-06-21T12:54:02+00:00

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

Is the fact that the following code works intentional ?

class S {
         function func() {
                 A::meth();
         }
}

class A {
         private $bar;

         function meth() {
                 $this->bar="bar";
         }

         function func() {
                 S::func();
                 echo "$this->bar\n";

         }
}


$a = new A;
$a->func();

... so A::$this is accessed through two static calls to different classes.

-- 
Ard

---

## #10693 — Johannes Schlueter — 2004-06-21T16:34:45+00:00

URL: https://externals.io/message/10676#10693 · In reply to: #10676

Hi,

yes, afaik it's intentional. This was made for making parent::foo() work.
Here's a shorter (at least a bit shorter *g*) example of this behavior:

<?php
class foo {
  function a() {
    bar::b();
  }
}
class bar {
  function b() {
    var_dump($this);
  }
}
$foo = new foo();
$foo->a(); // Calls bar::b()
?>

Prints:

object(foo)#1 (0) {
}

So in a static call $this holds the instance of the calling object.

johannes

Ard Biesheuvel wrote:

> 
> Is the fact that the following code works intentional ?
> 
> class S {
>          function func() {
>                  A::meth();
>          }
> }
> 
> class A {
>          private $bar;
> 
>          function meth() {
>                  $this->bar="bar";
>          }
> 
>          function func() {
>                  S::func();
>                  echo "$this->bar\n";
> 
>          }
> }
> 
> 
> $a = new A;
> $a->func();
> 
> ... so A::$this is accessed through two static calls to different classes.

---

## #10713 — Andi Gutmans — 2004-06-22T16:39:26+00:00

URL: https://externals.io/message/10676#10713 · In reply to: #10676

Yeah for BC sake, but if you define the function's as static explicitly it 
won't work.

At 01:54 PM 6/21/2004 +0200, Ard Biesheuvel wrote:

>Is the fact that the following code works intentional ?
>
>class S {
>         function func() {
>                 A::meth();
>         }
>}
>
>class A {
>         private $bar;
>
>         function meth() {
>                 $this->bar="bar";
>         }
>
>         function func() {
>                 S::func();
>                 echo "$this->bar\n";
>
>         }
>}
>
>
>$a = new A;
>$a->func();
>
>... so A::$this is accessed through two static calls to different classes.
>
>--
>Ard
