ID: 36707 User updated by: andreigurin at tiscali dot it Reported By: andreigurin at tiscali dot it -Status: Bogus +Status: Open Bug Type: Class/Object related Operating System: windows xp sp2 / linux centos / PHP Version: 4.4.2 New Comment:
You say : "Static methods which were not declared as static inherit $this from the parent scope". Did you say "PARENT SCOPE"??? Well, show me in the above code something like "class Bar extends Foo"... Foo isn't an ancestor for Bar class, and so Bar must not inherit $this from it. It's violating the OO paradigma, and it's a bug. As ask you once again to point me to the documentation describing such a behavior and, most of all, explaining it. Thanks!!!! Previous Comments: ------------------------------------------------------------------------ [2006-03-13 14:30:59] [EMAIL PROTECTED] It's not related to public/private modifiers at all. Static methods which were not declared as static inherit $this from the parent scope. This is the only way to preserve backward compatibility with PHP4 and it won't change in PHP5. ------------------------------------------------------------------------ [2006-03-13 14:29:41] andreigurin at tiscali dot it sorry, here is the php 4 code <?php error_reporting(E_ALL); class Foo { var $__prv; function Foo($v) { $this->__prv = $v; } function prv() { return $this->__prv; } function tst() { Bar::babar(); } } class Bar { function babar() { $this->__prv = 'a very very bad value'; print $this->prv(); } } $foo = new Foo('PRV VALUE'); $foo->tst(); ?> ------------------------------------------------------------------------ [2006-03-13 14:26:26] andreigurin at tiscali dot it Well, IMHO, such a behavior is violating the basics of OOP... Documentation is missing(am I right?). This is a BUG (a feature??? mmm...). In php4 (private & public modifiers missing), you may access every object field... <?php error_reporting(E_ALL); class Foo { protected $__prv; public function Foo($v) { $this->__prv = $v; } public function prv() { return $this->__prv; } function tst() { Bar::babar(); } } class Bar { public function babar() { $this->__prv = 'a very very bad value'; /* IS IT OK???!!!*/ print $this->prv(); } } $foo = new Foo('PRV VALUE'); $foo->tst(); /* $foo->__prv is modified now!!!*/ ?> ------------------------------------------------------------------------ [2006-03-13 10:42:24] andreigurin at tiscali dot it Are there a piece of documentation describing this behavior? Thanks for reply! ------------------------------------------------------------------------ [2006-03-13 10:37:58] [EMAIL PROTECTED] This is expected and it was done in order to keep compatibility with 4.x. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/36707 -- Edit this bug report at http://bugs.php.net/?id=36707&edit=1