#42021 [NEW]: Intance of same class, access directly private vars, dont using __get() method
| From: | o_gangrel at hotmail dot com | Date: | Tue, 17 Jul 2007 21:17:23 +0000 |
| Subject: | #42021 [NEW]: Intance of same class, access directly private vars, dont using __get() method | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-115155@lists.php.net to get a copy of this message | ||
From: o_gangrel at hotmail dot com
Operating system: Linux
PHP version: 5.2.3
PHP Bug Type: Scripting Engine problem
Bug description: Intance of same class, access directly private vars, dont using __get() method
Description:
------------
In a class, if instance this same class inside, the method __get() does
not is called.
Reproduce code:
---------------
class class_test {
private $sub_classes = array();
private $foo = "bar"; // Default value
public function __construct($n = 0)
{
for($i = 0; $i < $n; $i++) {
$this->sub_classes[] = new class_test(); // New "sub" instaces
}
if($n > 0) {
$this->foo = $n; // Change the default value on main instace
}
}
public function __get($name)
{
switch($name) {
case 'foo':
return '__get("foo") = '.$this->foo; // Getting the variable, changing
the value
break;
case 'subs':
$subs = '$this->foo = '.$this->foo."\n"; // Value of var on main
instace
foreach($this->sub_classes as $key => $sub_class) {
$subs.= "\$this->sub_classes[$key]->foo =
".$this->sub_classes[$key]->foo."\n"; // The value of variable on each
"sub" instace
}
return $subs;
break;
}
return false;
}
}
$test = new class_test(2); // Create the main instace, with 2 "sub"
instaces
echo $test->subs; // Show the variables
Expected result:
----------------
$this->foo = 2
$this->sub_classes[0]->foo = __get("foo") = bar
$this->sub_classes[1]->foo = __get("foo") = bar
Actual result:
--------------
$this->foo = 2
$this->sub_classes[0]->foo = bar
$this->sub_classes[1]->foo = bar
--
Edit bug report at http://bugs.php.net/?id=42021&edit=1
--
Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=42021&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=42021&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=42021&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=42021&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=42021&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=42021&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=42021&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=42021&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=42021&r=support
Expected behavior: http://bugs.php.net/fix.php?id=42021&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=42021&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=42021&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=42021&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=42021&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=42021&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=42021&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=42021&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=42021&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=42021&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=42021&r=mysqlcfg