# Problems with LSB

- Thread: https://externals.io/message/35348
- Original archive: https://news-web.php.net/php.internals/35348
- Started by Sebastian Deutsch on 2008-02-11T02:40:14+00:00
- Messages: 7
- 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

---

## #35348 — Sebastian Deutsch — 2008-02-11T02:40:14+00:00

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

Hello,

i've written the following code using Etiennes LSB. But I'm facing some 
problems.

<?php
     class A {
         function foo() {
             echo `get_called_class()`;
         }
     }

     class B extends A {
     }

     class C {
         function moo() {
             B::foo();
         }
     }

     B::foo();   // echos "B" - good

     $c = new C;
     $c->moo();  // echos "C" - wtf?? should be B
?>

Is it a bug, or did I miss anything?

Sebastian Deutsch

---

## #35365 — Lokrain — 2008-02-11T11:19:43+00:00

URL: https://externals.io/message/35348#35365 · In reply to: #35348

Hello, Sebastian

This seems to be a known bug http://bugs.php.net/bug.php?id=43408 and in
fact already assigned.

Fallbacks occur in static/self calls, as static/self resolve to "foo"
> and it returns foo as expected.
>
> However, when you do a parent::demo() you actually call bar::demo(),
> which is currently understood as a "fully qualified call": the caller is
> not passed.
>
> There are plans to allow explicit parent call to pass the caller, but
> this is *still under discussion*.

---

## #35367 — Sebastian Deutsch — 2008-02-11T11:39:06+00:00

URL: https://externals.io/message/35348#35367 · In reply to: #35365

Hello,

care... my case is slightly different. I was aware of that problem, but
in my case I call B::foo() from the main scope - it behaves right -
when I call it within the scope of C (same call) it behaves different.

This is different as described in the bug. The same call should
have the same output, not depending of the scope where I call it.

Sebastian

Lokrain schrieb:

> Hello, Sebastian
> 
> This seems to be a known bug http://bugs.php.net/bug.php?id=43408 and in
> fact already assigned.
> 
> Fallbacks occur in static/self calls, as static/self resolve to "foo"
> > […]

---

## #35369 — Sebastian Deutsch — 2008-02-11T13:00:58+00:00

URL: https://externals.io/message/35348#35369 · In reply to: #35367

Hello,

that's it. Even

$b = new B;
$b->foo();   // echos "B" - good

works.

Thank you!

*.sebastian

Sebastian Deutsch schrieb:
> Hello,
> 
> care... my case is slightly different. I was aware of that problem, but
> in my case I call B::foo() from the main scope - it behaves right -
> when I call it within the scope of C (same call) it behaves different.
> 
> This is different as described in the bug. The same call should
> have the same output, not depending of the scope where I call it.
> 
> Sebastian
> 
> Lokrain schrieb:
> 
> > […]

---

## #35370 — Etienne Kneuss — 2008-02-11T13:03:38+00:00

URL: https://externals.io/message/35348#35370

Hello,

your foo function is not defined as static, hence no static call is done.
> Strict Standards: Non-static method A::foo() should not be called statically, assuming $this from incompatible context ...

Define your method as static and it should work just fine.

Regards

On Feb 11, 2008 12:39 PM, Sebastian Deutsch

<sebastian.deutsch@9elements.com> wrote:
> Hello,
>
> care... my case is slightly different. I was aware of that problem, but
> in my case I call B::foo() from the main scope - it behaves right -
> when I call it within the scope of C (same call) it behaves different.
>
> This is different as described in the bug. The same call should
> have the same output, not depending of the scope where I call it.
>
> Sebastian
>
> Lokrain schrieb:
>
>
> > […]
>
>
> --
> 
> 
>
>
>

-- 
Etienne Kneuss
http://www.colder.ch

Men never do evil so completely and cheerfully as
when they do it from a religious conviction.
-- Pascal

---

## #35371 — Moritz Bechler — 2008-02-11T13:03:46+00:00

URL: https://externals.io/message/35348#35371 · In reply to: #35348

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

My original reply missed the list :|

Hi,

>
> i've written the following code using Etiennes LSB. But I'm facing some
> problems.
>
> <?php
>     class A {
>         function foo() {
>             echo `get_called_class()`;
>         }
>     }
>
>     class B extends A {
>     }
>
>     class C {
>         function moo() {
>             B::foo();
>         }
>     }
>
>     B::foo();   // echos "B" - good
>
>     $c = new C;
>     $c->moo();  // echos "C" - wtf?? should be B
> ?>
>
> Is it a bug, or did I miss anything?
>

If you mark your function "foo" static - as you should - its "BB" for me.

Moritz Bechler



-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.7 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHsEeydLVsKnwBr9YRAu8LAJ4+/pnKZ1YzM0wN9k7Vg9eyWaZnUQCeKTrO
hgv4dRz1YtLqHRgagUOKwQA=
=cxLj
-----END PGP SIGNATURE

---

## #35544 — Jingcheng Zhang — 2008-02-18T03:26:20+00:00

URL: https://externals.io/message/35348#35544 · In reply to: #35370

Hello Etienne,

If static:: in static context behaves like $this in object context, it would
be much meaningful. If we introduce the "meta class" concept in PHP, then
each class is an instance of the meta class, thus we can treat a class as an
object, and then it is natural that static members follow the rules of
inheritance.

This may matches the running style of PHP better, which differs from other
languages as PHP (under web environment) activates classes when request
arrives, and shutdown them when request finishes, while other
Object-Oriented languages persist classes and objects in memory.



> Hello,
>
> your foo function is not defined as static, hence no static call is done.
> > […]
> statically, assuming $this from incompatible context ...
>
> Define your method as static and it should work just fine.
>
> Regards
>
> On Feb 11, 2008 12:39 PM, Sebastian Deutsch
>
> <sebastian.deutsch@9elements.com> wrote:
> > […]
> in
> > […]
> is
> > […]
>
> --
> Etienne Kneuss
> http://www.colder.ch
>
> Men never do evil so completely and cheerfully as
> when they do it from a religious conviction.
> -- Pascal
>
> --
> 
> 
>
>


-- 
Best regards,
Jingcheng Zhang
Room 304, Dormitory 26 of Yuquan Campus, Zhejiang University
P.R.China
