Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:33552 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 64514 invoked by uid 1010); 30 Nov 2007 16:24:40 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 64499 invoked from network); 30 Nov 2007 16:24:40 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Nov 2007 16:24:40 -0000 Authentication-Results: pb1.pair.com header.from=diogin@gmail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=diogin@gmail.com; spf=pass; sender-id=pass 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: diogin@gmail.com X-Host-Fingerprint: 209.85.198.187 rv-out-0910.google.com Received: from [209.85.198.187] ([209.85.198.187:48769] helo=rv-out-0910.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 84/08-16143-44930574 for ; Fri, 30 Nov 2007 11:24:37 -0500 Received: by rv-out-0910.google.com with SMTP id k15so2151171rvb for ; Fri, 30 Nov 2007 08:24:34 -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:to:subject:cc:in-reply-to:mime-version:content-type:references; bh=enwEhepJTI6X4ZOVMe53zOUQLEQZ9g7ELHiGlPwF+D4=; b=cs7BaiLH0UsD1AUS111o7CgLfhfbyKMLSBTiFy3uHpLzN0Uis7VPOyhHQT4JCYF5quawRvQGOCp7ya1YjoYO+eGGn+PgymPuxX3od+AomU2SqROl1X+pmQ1cHSijiZIS3OgKu7JtdAyUtVw2mF1Hxdh8jm5+Paz036Q2SKFopuU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; b=gyeQC85saWeMW9uEuJP/dR26gkT9BnRguc1mGuu/t6X1jL8zXSZjtrCAt6gpAHdJpdvz7qESoCMsRxkh+WgZmI0eeSvxfQJ8FSsX0Ql5KhuyMnLgROFVuchsjn91dM3xgjto1HUeswrkx1R15YQ6IG0c3QzygTqwQDYdvNoy+KY= Received: by 10.140.177.15 with SMTP id z15mr246993rve.1196439869743; Fri, 30 Nov 2007 08:24:29 -0800 (PST) Received: by 10.140.225.20 with HTTP; Fri, 30 Nov 2007 08:24:29 -0800 (PST) Message-ID: Date: Sat, 1 Dec 2007 00:24:29 +0800 To: "Etienne Kneuss" Cc: "Marco Kaiser" , internals@lists.php.net In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_255_11183891.1196439869760" References: <474ff865.0d135e0a.4536.ffffa229@mx.google.com> Subject: Re: [PHP-DEV] private properties .... From: diogin@gmail.com ("Jingcheng Zhang") ------=_Part_255_11183891.1196439869760 Content-Type: text/plain; charset=ISO-2022-JP Content-Transfer-Encoding: 7bit Content-Disposition: inline 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, and there is also a bug here, consider the following example: 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: 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 ------=_Part_255_11183891.1196439869760--