#42021 [Bgs]: Intance of same class, access directly private vars, dont using __get() method
| From: | o_gangrel at hotmail dot com | Date: | Tue, 31 Jul 2007 21:21:55 +0000 |
| Subject: | #42021 [Bgs]: Intance of same class, access directly private vars, dont using __get() method | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-115615@lists.php.net to get a copy of this message | ||
ID: 42021
User updated by: o_gangrel at hotmail dot com
Reported By: o_gangrel at hotmail dot com
Status: Bogus
Bug Type: Scripting Engine problem
Operating System: Linux
PHP Version: 5.2.3
New Comment:
Unfortunately an other bug I report, and have no attencion... and other
will (may be from the PHP crew) report and solve the bug.
Well... every thing I report is a bogus... then I will just use de PHP
and not report, only pray, to the "bogus" in future have solved.
Good luck.
Previous Comments:
------------------------------------------------------------------------
[2007-07-18 15:33:52] o_gangrel at hotmail dot com
Sou you mean, when I have an instace of the class itself, the method
__get() will not called? It not sounds good to mee! And the variable is
a PRIVATE variable, and it can't be accessed only becouse the class is
the same and the instace isn't.
------------------------------------------------------------------------
[2007-07-17 22:36:12] johannes@php.net
Should have been "restricted" instead of "rejected"...
------------------------------------------------------------------------
[2007-07-17 22:12:43] johannes@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
The visibility modifiers work on a per class basis and is not rejected
to the same object.
------------------------------------------------------------------------
[2007-07-17 21:17:22] o_gangrel at hotmail dot com
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 this bug report at http://bugs.php.net/?id=42021&edit=1