Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:21330 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 15796 invoked by uid 1010); 23 Dec 2005 12:28:44 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 15780 invoked from network); 23 Dec 2005 12:28:44 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Dec 2005 12:28:44 -0000 X-Host-Fingerprint: 194.109.193.120 unknown Linux 2.4/2.6 Received: from ([194.109.193.120:51047] helo=mx1.moulin.nl) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id 41/E4-15227-C7DEBA34 for ; Fri, 23 Dec 2005 07:28:44 -0500 Received: from localhost (localhost [127.0.0.1]) by mx1.moulin.nl (Postfix) with ESMTP id 6A2EC1932CD for ; Fri, 23 Dec 2005 13:28:44 +0100 (CET) Received: from mx1.moulin.nl ([127.0.0.1]) by localhost (moulin [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 05391-07 for ; Fri, 23 Dec 2005 13:28:41 +0100 (CET) Received: from [192.168.1.16] (bspr.xs4all.nl [194.109.161.228]) by mx1.moulin.nl (Postfix) with ESMTP id 99DA81938C6 for ; Fri, 23 Dec 2005 13:28:41 +0100 (CET) Message-ID: <43ABED74.8020600@iamjochem.com> Date: Fri, 23 Dec 2005 13:28:36 +0100 User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317) X-Accept-Language: en-us, en MIME-Version: 1.0 To: php internals X-Enigmail-Version: 0.89.5.0 X-Enigmail-Supports: pgp-inline, pgp-mime Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: amavisd-new at moulin.nl Subject: accessing protected method of 'delegated' object ... From: jochem@iamjochem.com (Jochem Maas) 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? 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. if this behaviour is expected I'd be very grateful if anyone could shed some light on why. 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