Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:10469 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 44404 invoked by uid 1010); 15 Jun 2004 14:32:57 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 44338 invoked by uid 1007); 15 Jun 2004 14:32:56 -0000 Message-ID: <20040615143256.44336.qmail@pb1.pair.com> To: internals@lists.php.net, Antony Dovgal Date: Tue, 15 Jun 2004 16:32:55 +0200 References: <20040615175918.57e77cbb.tony2001@phpclub.net> Lines: 57 User-Agent: KNode/0.7.6 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Posted-By: 217.235.242.192 Subject: Re: Weird behaviour of private attribute + overloaded method From: schlueter@phpbar.de (Johannes Schlueter) Hi, that's imho expected behaviour. To quote http://www.php.net/zend-engine-2.php | Protected member variables can be accessed in classes extending the class | they are declared in, whereas private member variables can only be | accessed by the class they belong to. And $id belongs to the base class and not to the extended. What else should be the difference between private and protected? johannes Antony Dovgal wrote: > Hi all! > > What do you expect from this code? > > > class Foo{ > private $id = false; > public function getId () { > return $this->id; > } > public function setId ($id) { > return $this->id = $id; > } > > } > > class Bar extends Foo { > public function setId ($id) { > return $this->id = $id; > } > } > > $b = new Bar; > $b->setId(123); > var_dump($b->getId()); > > ?> > > It outputs 'bool(false)', while I expect it to print 'int(123)'. > > Changing private $id to public or protected solves the problem. > Adding getId() method to the Bar solves it too, but this is obviously > rather silly solution. > > Am I missing something and this is really expected behaviour ? > > --- > WBR, > Antony Dovgal aka tony2001 > tony2001@phpclub.net || antony@dovgal.com