ID: 36707
User updated by: andreigurin at tiscali dot it
Reported By: andreigurin at tiscali dot it
Status: Open
Bug Type: Class/Object related
Operating System: windows xp sp2 / linux centos /
PHP Version: 4.4.2
New Comment:
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();
?>
Previous Comments:
------------------------------------------------------------------------
[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();
?>
------------------------------------------------------------------------
[2006-03-13 09:19:01] [EMAIL PROTECTED]
Works fine both with 4.x and 5.x.
No bug here.
------------------------------------------------------------------------
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