Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:33556 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 75892 invoked by uid 1010); 30 Nov 2007 17:06:45 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 75877 invoked from network); 30 Nov 2007 17:06:44 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Nov 2007 17:06:44 -0000 Authentication-Results: pb1.pair.com smtp.mail=ekneuss@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ekneuss@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.198.187 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: ekneuss@gmail.com X-Host-Fingerprint: 209.85.198.187 rv-out-0910.google.com Received: from [209.85.198.187] ([209.85.198.187:13446] helo=rv-out-0910.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 92/99-16143-22340574 for ; Fri, 30 Nov 2007 12:06:43 -0500 Received: by rv-out-0910.google.com with SMTP id k15so2166815rvb for ; Fri, 30 Nov 2007 09:06:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:references:x-google-sender-auth; bh=hX/IZWIFGeD6BDwDS+OxxHrixlpykitWXn/2YrNquXY=; b=nc8jRrMR3E6mVBQdqH8zBjIQjU7p76Ok+NJNBjhPfFf3IB7iQbJ+JJmq4zou0vqB17liBGa+CsRDINtqvBmhr1nmyOH+fCP8b+wJx7aT/DW2ey347Ec7zRRHzBOI6WT0sbtlGNgPrI77i3jwq215gZWsFLAtZktL5vXh/1wF9/g= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=received:message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:references:x-google-sender-auth; b=wPN56ykMBK8UKjXN3DzNREfHaN5EpF5SY632fOfuQNdqnhWMHV9xlP9ZC2X9f+pslrsT0s9XYBkIXS31QMzXUsBOzTemMitrG8JeVTPsO4lh1CC/MMpREgCBj14HHyQGxviIQKcqrvZsxxJRktCIFU0Mn3+068uqsyV8UTgLZK0= Received: by 10.143.16.9 with SMTP id t9mr997723wfi.1196442400111; Fri, 30 Nov 2007 09:06:40 -0800 (PST) Received: by 10.70.41.7 with HTTP; Fri, 30 Nov 2007 09:06:39 -0800 (PST) Message-ID: Date: Fri, 30 Nov 2007 18:06:39 +0100 Sender: ekneuss@gmail.com To: "Jingcheng Zhang" Cc: "Marco Kaiser" , internals@lists.php.net In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_1276_1308016.1196442399983" References: <474ff865.0d135e0a.4536.ffffa229@mx.google.com> X-Google-Sender-Auth: 626af5e11f6eb2b1 Subject: Re: [PHP-DEV] private properties .... From: colder@php.net ("Etienne Kneuss") ------=_Part_1276_1308016.1196442399983 Content-Type: text/plain; charset=ISO-2022-JP Content-Transfer-Encoding: 7bit Content-Disposition: inline Hello, On Nov 30, 2007 5:24 PM, Jingcheng Zhang wrote: > Hi Etienne, > Is "private" only an access limiter between classes?If so, I think > private > properties and methods should be OK to be extended into the child class, > but > currently that's not the case, You're describing what "protected" does here. About the "bug", var_dump in 5_3 already states the origin of the private var: will produce: object(B)#1 (2) { ["a":"A":private]=> int(2) ["b":protected]=> int(3) } and there is also a bug here, consider the > following example: > > class P { > private $name = 'hello'; > } > class C extends P { > public function f() { > echo $this->name; > } > } > $o = new C(); > var_dump($o); // object(C)#1 (1) { ["name:private"]=> string(5) "hello" } > $o->f(); // Notice: Undefined property: C::$name in > D:\Development\Workspace\index.php on line 7 > ?> > > When using var_dump on $o, it shouldn't display the private property > "name" > here as it is not extended. If we allow private properties be extended > into > the child class, then the codes above and following should both work OK: > > class P { > private $name = 'hello'; > } > class C extends P { > public function f() { > $o = new P(); > echo $o->name; // Incorrect, as the code scope is not class P > } > public function g() { > echo $this->name; // This should be OK, as $name is extended from > P, > and is property of class C, not class P > } > } > $c = new C(); > $c->f(); > $c->g(); > ?> > > > On Nov 30, 2007 10:08 PM, Etienne Kneuss wrote: > > > Hello, > > > > On 11/30/07, Marco Kaiser wrote: > > > > > > Conclusion: > > > 1. Why i can access a private property from a different class instance > > > (name) but same type ? > > > $aa and $bb are instances of aaa but not the same. > > > 2. This doesnt works if cc is a own class with same property name (ie. > > > interface or something like this) > > > > > > The check whether a class property/method is accessible is based on the > > class of the scope you're in. It's not based on the instance. Note that > > encapsulation is still conserved as private properties are accessible > only > > from methods of the class they're defined in. It also allows you to work > > with static methods that access private properties. > > > > 3. Is it a bug that i can't use same property name in my child class? > > > (normaly the parent property isnt visible to the child) > > > cc extends aaa. > > > > > > I'm not sure what you mean. As you can do: > > > > class A { private $foo = 2; } > > class B extends A { private $foo = 3; public function foo() { echo > > $this->foo; } } > > $b = new B; $b->foo(); // 3 > > > > > > Thats just some questions :) > > > > > > -- Marco > > > > > > -- > > > PHP Internals - PHP Runtime Development Mailing List > > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > > > > > > > > > > > -- > > Etienne Kneuss > > http://www.colder.ch > > > > Men never do evil so completely and cheerfully as > > when they do it from a religious conviction. > > -- Pascal > > > > > > -- > Best regards, > Jingcheng Zhang > Room 304, Dormitory 26 of Yuquan Campus, Zhejiang University > P.R.China > -- Etienne Kneuss http://www.colder.ch Men never do evil so completely and cheerfully as when they do it from a religious conviction. -- Pascal ------=_Part_1276_1308016.1196442399983--