Hello,

I posted the same topic on the general mailing list, but it appears this can
be posted here, as it is open to feedbacks and is about PHP implementation
of static functions.

I'm wondering if the following behaviour is a bug or a feature. The case is
quite complex, so let me explain my point of view.
here is the source :

<?php

class MyTest {
    public function myfunc() {
        echo get_class($this);
    }
}
class MySecondTest {
    public function test() {
        MyTest::myfunc();
    }
}

$test = new MySecondTest();
$test->test(); //output: "MySecondTest"

?>

In this case, $this is MySecondTest, which is relevant as it is the last
object context. But to my mind, this code should not work like this.

Imagine you are the developer of function MyTest. You want your code to
interact with other classes and being bugproof. 'MyTest' class here seems
OK: $this is expected to be 'MyTest' because function myfunc() is expected
to be called in a non-static context.

Programmer of the second function created this bug and this unattended
behaviour.

Maybe this can be done :
1/ Forbid calling the function in static context (How can I test this ?
$this is not NULL there !).
2/ (or/and) Raise an error if a non static function is called as a static
one (if E_STRICT is set, strict warning is already raised).
3/ Create two functions with the same name, one static and the other one
not. Unfortunately, this can't be done (yet ?).


What do you think ? What's your point of view on this ? I want your
feedbacks before opening a bug ticket, as it is not strictly a "bug"...

Reply via email to