D
D
developer2012-02-14 20:03:19
PHP
developer, 2012-02-14 20:03:19

Is it correct to comment PHP BUG#61084?

bugs.php.net/bug.php?id=61084
Apparently people don't understand my English.
The situation is simple and demonstrates the incorrect behavior of the interpreter, which is that when using a non-static class function ( method A::m() ) inside an object of another class ( class C ) as a class function, the variable context inside the function ( A::m( ) ) declared in the first class ( A ) via the static keyword switches to the class context of the object ( C ) in which the method is called.
PS. And it’s not clear in Russian, right? Run, please, the given code (10 lines) and read it - everything will immediately become obvious.

Answer the question

In order to leave comments, you need to log in

5 answer(s)
S
Sergey Beresnev, 2012-02-15
@developer

Surprisingly, this behavior is mentioned in the manual: http://ru.php.net/manual/en/language.oop5.basic.php#language.oop5.basic.class.this

M
Max, 2012-02-14
@7workers

do error_reporting(E_ALL|E_STRICT); and see the warning you expect. I don't see the bug. As you wrote there, your code looks strange. If you do E_STRICT reporting, then PHP will tell you about it. If you don't want to hear about it, it's up to you, but then it's easy to get confused.

X
xmeoff, 2012-02-14
@xmeoff

They answered you: you write incorrect code, and therefore you get an error. And what difference does it make in her description? a mistake is a mistake.
And according to the 2nd example, an explanation is also given: you cannot call a non-static function as a static one. In your example, the function m is actually called as a non-static function, hence the unusual behavior.

D
developer, 2012-02-15
@developer

yes, I wrote a question on Habré before I could explain it to a support representative, it’s really so conceived.

D
developer, 2012-02-15
@developer

All comments, except for the comment of sectus, are not given in the case and speak rather of a misunderstanding of the issue. special thanks to sectus, perhaps the documentation will be extended for static, but in any case, it turned out that the static context behaves in this aspect more like a $this context than like a self context, which was a surprise, not explicitly documented.
I’ll tell you about E_STRICT and the history of finding this example: PHP was installed on one of the developer’s machines with standard settings, when he encountered oddities in his work, he handed over the code to me where I immediately saw Strict, however, even in this case, the behavior seemed unexpected to me and I wanted to figure out what case. As of PHP 5.4, E_STRICT will be part of E_ALL and that's great!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question