Newsgroups: php.internals,php.internals Path: news.php.net Xref: news.php.net php.internals:10472 php.internals:10473 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 87530 invoked by uid 1010); 15 Jun 2004 14:17:46 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 87417 invoked by uid 1007); 15 Jun 2004 14:17:45 -0000 To: internals@lists.php.net, Antony Dovgal Message-ID: <40CF0378.4030705@memefeeder.com> Date: Tue, 15 Jun 2004 14:11:04 +0000 User-Agent: Mozilla Thunderbird 0.5 (X11/20040301) X-Accept-Language: en-us, en MIME-Version: 1.0 CC: internals@lists.php.net References: <20040615175918.57e77cbb.tony2001@phpclub.net> In-Reply-To: <20040615175918.57e77cbb.tony2001@phpclub.net> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Posted-By: 213.210.24.171 Subject: Re: Weird behaviour of private attribute + overloaded method From: ray.hilton@memefeeder.com (Ray Hilton) Hi, This is expected since the property is marked private, meaning its only accessable within its own scope, not for extended classes. For that you need to use protected, as you mention. ray - e: ray.hilton@memefeeder.com w: http://www.memefeeder.com 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