Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:21332 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 22489 invoked by uid 1010); 23 Dec 2005 17:55:28 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 22474 invoked from network); 23 Dec 2005 17:55:28 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Dec 2005 17:55:28 -0000 X-Host-Fingerprint: 81.169.182.136 ajaxatwork.net Linux 2.4/2.6 Received: from ([81.169.182.136:34109] helo=strato.aixcept.de) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id DB/70-15032-01A3CA34 for ; Fri, 23 Dec 2005 12:55:28 -0500 Received: from [192.168.1.3] (dslb-084-063-009-251.pools.arcor-ip.net [84.63.9.251]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by strato.aixcept.de (Postfix) with ESMTP id D011835C1D9; Fri, 23 Dec 2005 18:55:23 +0100 (CET) Date: Fri, 23 Dec 2005 18:55:29 +0100 Reply-To: Marcus Boerger X-Priority: 3 (Normal) Message-ID: <194633301.20051223185529@marcus-boerger.de> To: Jochem Maas Cc: php internals In-Reply-To: <43ABED74.8020600@iamjochem.com> References: <43ABED74.8020600@iamjochem.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] accessing protected method of 'delegated' object ... From: helly@php.net (Marcus Boerger) Hello Jochem, Friday, December 23, 2005, 1:28:36 PM, you wrote: > if I have an object with a given base class and it > has an object as a property which has the same base class > should I or should I not be able to call a protected method > on the contained (delegated) from the first (container) object? of course not it is a different object. If we had subclasses this would be different. > currently I am not able to do what I thought should work, below > is an example which hopefully makes it clear what i'm going on about. Just to make this clear: your code as given below must fail because it violates visibility/inheritance rules. > if this behaviour is expected I'd be very grateful if anyone > could shed some light on why. The problem is that we neither have 'friend' which would help you here nor do we have a second visibility rule set (however no other language supports that) and also programming languages do support grant models like databases do. > kind regards, > Jochem $>> php -r ' > abstract class A { > function test() { $this->doit(); } > protected function doit() { echo "A\n"; } > } > class B extends A { > protected function doit() { parent::doit(); echo "B\n"; } > } > class C extends A { > function __construct() { $this->delegate = new B; } > protected function doit() { $this->delegate->doit(); echo "C\n"; } > /* > the problem can be solved here by chaing the preceeding line of code to: > protected function doit() { $this->delegate->test(); echo "C\n"; } > but that does not solve the realworld issue I had regarding this :-) > */ > } > $b = new B; $c = new C; > $b->test(); > $c->test(); > ' > A > B > Fatal error: Call to protected method B::doit() from context 'C' in Command line code on line 5 Best regards, Marcus