ID:               36707
 User updated by:  andreigurin at tiscali dot it
 Reported By:      andreigurin at tiscali dot it
 Status:           Bogus
 Bug Type:         Class/Object related
 Operating System: windows xp sp2 / linux centos /
 PHP Version:      4.4.2
 New Comment:

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();

?>


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

[2006-03-13 09:19:01] [EMAIL PROTECTED]

Works fine both with 4.x and 5.x.
No bug here.

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

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

Look here: This happens in 4.xxx versions, and in 5.xxx, my code is for
version 5.
I reported the first version i tested it. It equally falls on 4 an on
5.

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

[2006-03-13 09:13:11] judas dot iscariote at gmail dot com

your test results :

Fatal error: Using $this when not in object context..

and the code you mention cannot run in PHP4, since PHP doesn't have
public, private modifiers...

what are you talking about ?

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

[2006-03-12 19:44:24] andreigurin at tiscali dot it

Description:
------------
$this keyword visibility is violated if accessed from a function
external to a class. This happens in 4.xxx versions, and in 5.xxx,
Tested on Window 2000, Windows Xp sp2, Linux Centos(3.7?), Red hat, and
some other Linux based systems

Reproduce code:
---------------
class Foo {
    private $__prv;
    public function __constructor($v) {
        $this->__prv = $v;
    }
    public function do_something() {
        bla bla bla...
        hack();
    }
    public function prv() {
        return $this->__prv;
    }
}
function hack() {
    $this->__prv = 'A very bad value!';
}
$foo = new Foo('A good __prv value');
$foo->do_something();
print $foo->prv();

Expected result:
----------------
Triggered error: 
bla bla bla undefined variable this in file.php on line ...
Output:
A good __prv value

Actual result:
--------------
Output:
A very bad value


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


-- 
Edit this bug report at http://bugs.php.net/?id=36707&edit=1

Reply via email to