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:

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.


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

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

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

[2006-03-13 10:34:12] andreigurin at tiscali dot it

ok, try this

<?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() {
                print $this->prv();
        }
}

$foo = new Foo('PRV VALUE');
$foo->tst();

?>

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

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