Re: issue with inheriting private property from abstract class in php5rc3

From: Date: Wed, 23 Jun 2004 21:19:03 +0000
Subject: Re: issue with inheriting private property from abstract class in php5rc3
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-188914@lists.php.net to get a copy of this message
Do you have E_STRICT turned on? If not, I believe PHP5 lets you access private / protected vars wherever you want. On Wed, 23 Jun 2004 13:40:48 -0400, Chris <auslander@tampabay.rr.com> wrote: > > 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() { > $this->test = 0; > } > > public function addToTest($i) { > $this->test += $i; > } > } > > $t = new TestInstance(); > $t->addToTest(3); > > var_dump($t); > > // test var SHOULD be private > echo "private test (shouldn't be able to access it directly, but i can): > ".$t->test."\n\n"; > > /* > output > ------------------------------- > object(TestInstance)#1 (2) { > ["test:private"]=> > NULL > ["test"]=> > int(3) > } > private test (shouldn't be able to access it directly, but i can): 3 > */ > ?> > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- paperCrane --Justin Patrin--

« previous php.general (#188914) next »