Re: issue with inheriting private property from abstract class in php5rc3
| From: | Marek Kilimajer | Date: | Thu, 24 Jun 2004 08:35:42 +0000 |
| Subject: | Re: issue with inheriting private property from abstract class in php5rc3 | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-188934@lists.php.net to get a copy of this message | ||
Curt Zirzow wrote --- napísal::
* Thus wrote Marek Kilimajer:Right, ["Test::test:private"] would be betterChris wrote --- nap?sal::I think one could argue that that test:private shouldn't even be there. To me that test:private would imply that is TestIntance's private variable.if anyone can, would you please explain why the below code does what it does? I would expect $this->test in TestInstance to refer to the inherited $test from Test. Using php5RC3. Thanks. <?php abstract class Test { private $test; abstract public function addToTest($i); } class TestInstance extends Test { public function __construct() {... The variable is private for Test, so TestInstance does not have access to it. By assigning 0 to $this->test in the constructor of TestInstance, you create a new property of TestInstance that is public (the default). var_dump() shows it clearly: object(TestInstance)#1 (2) { ["test:private"]=> NULL <---- belongs to Test$this->test = 0;}["test"]=> int(3) <---- belongs to TestInstance}