#34893 [NEW]: PHP5.1 overloading, Cannot access private property

From: Date: Mon, 17 Oct 2005 14:58:28 +0000
Subject: #34893 [NEW]: PHP5.1 overloading, Cannot access private property
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-86650@lists.php.net to get a copy of this message
From:             kai at meder dot info
Operating system: WinXP
PHP version:      5.1.0RC1
PHP Bug Type:     Scripting Engine problem
Bug description:  PHP5.1 overloading, Cannot access private property 

Description:
------------
chaining of objects using __get() works like a charm, however if using
chaining and using __set() at the end of the chain to set a property, php
fails reporting: "Fatal error: Cannot access private property A::$p in
<file> on line <line>"

please keep in mind that i'm using php5.1 (RC1), chaining should work in
this version, doesn't it?

posted reproduce code from
http://www.sitepoint.com/forums/showthread.php?p=2230679#post2230679


Reproduce code:
---------------
class A {
	private $p;
	function __get($name){
		return $this->$name;
	}
	function __set($name, $value) {
		$this->$name = $value;
	}
}
class B {
	private $t;
	function __get($name){
		return $this->$name;
	}
	function __set($name, $value) {
		$this->$name = $value;
	}
}
$a = new A;
$b = new B;
$a->p = $b;
$b->t = "foo";

echo $a->p->t;
$a->p->t = "bar";
echo $a->p->t;

Expected result:
----------------
foobar

Actual result:
--------------
foo
Fatal error: Cannot access private property A::$p in...

-- 
Edit bug report at http://bugs.php.net/?id=34893&edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=34893&r=trysnapshot4
Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=34893&r=trysnapshot50
Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=34893&r=trysnapshot51
Fixed in CVS:                http://bugs.php.net/fix.php?id=34893&r=fixedcvs
Fixed in release:            http://bugs.php.net/fix.php?id=34893&r=alreadyfixed
Need backtrace:              http://bugs.php.net/fix.php?id=34893&r=needtrace
Need Reproduce Script:       http://bugs.php.net/fix.php?id=34893&r=needscript
Try newer version:           http://bugs.php.net/fix.php?id=34893&r=oldversion
Not developer issue:         http://bugs.php.net/fix.php?id=34893&r=support
Expected behavior:           http://bugs.php.net/fix.php?id=34893&r=notwrong
Not enough info:             http://bugs.php.net/fix.php?id=34893&r=notenoughinfo
Submitted twice:             http://bugs.php.net/fix.php?id=34893&r=submittedtwice
register_globals:            http://bugs.php.net/fix.php?id=34893&r=globals
PHP 3 support discontinued:  http://bugs.php.net/fix.php?id=34893&r=php3
Daylight Savings:            http://bugs.php.net/fix.php?id=34893&r=dst
IIS Stability:               http://bugs.php.net/fix.php?id=34893&r=isapi
Install GNU Sed:             http://bugs.php.net/fix.php?id=34893&r=gnused
Floating point limitations:  http://bugs.php.net/fix.php?id=34893&r=float
No Zend Extensions:          http://bugs.php.net/fix.php?id=34893&r=nozend
MySQL Configuration Error:   http://bugs.php.net/fix.php?id=34893&r=mysqlcfg


Thread (9 messages)

« previous php.bugs (#86650) next »