Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:3388 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 8461 invoked from network); 12 Jul 2003 16:12:28 -0000 Received: from unknown (HELO mail.zend.com) (192.117.235.230) by pb1.pair.com with SMTP; 12 Jul 2003 16:12:28 -0000 Received: (qmail 11313 invoked from network); 12 Jul 2003 16:12:19 -0000 Received: from localhost (HELO andi-home.zend.com) (127.0.0.1) by localhost with SMTP; 12 Jul 2003 16:12:19 -0000 Message-ID: <5.1.0.14.2.20030712191532.027fcea8@127.0.0.1> X-Sender: andi@127.0.0.1 X-Mailer: QUALCOMM Windows Eudora Version 5.1 Date: Sat, 12 Jul 2003 19:16:51 +0200 To: Greg Beaver ,internals@lists.php.net In-Reply-To: <3F0F47D2.80208@chiaraquartet.net> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed Subject: Re: [PHP-DEV] Questionable private $varname behavior From: andi@zend.com (Andi Gutmans) References: <3F0F47D2.80208@chiaraquartet.net> At 07:27 PM 11/7/2003 -0400, Greg Beaver wrote: >Hi, a discussion on php.general led to the discovery of this oddly legal >script: > > class dog { > // declare two private variables > private $Name; > private $DogTag; > > public function bark() { > print "Woof!\n"; > } > > public function printName() { > print $this->Name; // prints nothing! > } > } > > // new class, for testing derived stuff > class poodle extends dog { > public function bark() { > print "Yip!\n"; > } > } > > // I now create an instance of the > // derived class > $poppy = new poodle; > > // and set its private property > $poppy->Name = "Poppy"; > print $poppy->Name. "\n"; > $poppy->printName(); > print_r($poppy); >?> > >outputs: > >Poppy >poodle Object >( > [Name:private] => > [DogTag:private] => > [Name] => Poppy >) > >Is this expected behavior or should I open a bug? Seems to be expected behavior to me. poodle doesn't *know* the private variable "Name" so when you use $poppy->Name it declares a public member instead. As printName() is inherited from the base class it accesses the private member and not the public one. Andi