ID:               36707
 Updated by:       [EMAIL PROTECTED]
 Reported By:      andreigurin at tiscali dot it
-Status:           Open
+Status:           Bogus
 Bug Type:         Class/Object related
 Operating System: windows xp sp2 / linux centos /
 PHP Version:      4.4.2
 New Comment:

I didn't say a word about class inheritance.

function foo() {
//parent scope
bar(); //child scope inside
}
This is what I mean.

Feel free to invest some time into improving the documentation and
explaining to others why it works the way it works. Please contact
phpdoc@lists.php.net with all further questions.
And stop reopening the report, there is no bug.


Previous Comments:
------------------------------------------------------------------------

[2006-03-14 09:09:13] andreigurin at tiscali dot it

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!!!!

------------------------------------------------------------------------

[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!

------------------------------------------------------------------------

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

Reply via email to