Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:33288 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 10278 invoked by uid 1010); 19 Nov 2007 06:43:51 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 10263 invoked from network); 19 Nov 2007 06:43:51 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Nov 2007 06:43:51 -0000 Authentication-Results: pb1.pair.com header.from=larry@garfieldtech.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=larry@garfieldtech.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain garfieldtech.com from 76.96.30.80 cause and error) X-PHP-List-Original-Sender: larry@garfieldtech.com X-Host-Fingerprint: 76.96.30.80 qmta08.emeryville.ca.mail.comcast.net Received: from [76.96.30.80] ([76.96.30.80:46736] helo=QMTA08.emeryville.ca.mail.comcast.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D1/6F-31009-6A031474 for ; Mon, 19 Nov 2007 01:43:51 -0500 Received: from OMTA09.emeryville.ca.mail.comcast.net ([76.96.30.20]) by QMTA08.emeryville.ca.mail.comcast.net with comcast id EWH21Y0080S2fkC0A01B00; Mon, 19 Nov 2007 06:43:51 +0000 Received: from earth.ufp ([71.228.13.89]) by OMTA09.emeryville.ca.mail.comcast.net with comcast id EWjq1Y0011vH2xB0800000; Mon, 19 Nov 2007 06:43:50 +0000 X-Authority-Analysis: v=1.0 c=1 a=tr97OxPdtMOJk0y3nXEA:9 a=LdNA72Uz2frSS1bAiOcA:7 a=XdT4oygjcbRFkRmI9XPRK-wDIQgA:4 a=FHBbIDN7CdwA:10 a=LY0hPdMaydYA:10 Received: from localhost (localhost [127.0.0.1]) by earth.ufp (Postfix) with ESMTP id 93921D8314 for ; Mon, 19 Nov 2007 00:43:46 -0600 (CST) Received: from earth.ufp ([127.0.0.1]) by localhost (earth.ufp [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id U8HavrqPu4fq for ; Mon, 19 Nov 2007 00:43:46 -0600 (CST) Received: from vulcan.ufp (vulcan.ufp [192.168.42.4]) by earth.ufp (Postfix) with ESMTP id 7F728D8308 for ; Mon, 19 Nov 2007 00:43:36 -0600 (CST) To: internals@lists.php.net Date: Mon, 19 Nov 2007 00:44:25 -0600 User-Agent: KMail/1.9.6 (enterprise 0.20070907.709405) References: <1195140437.23612.5.camel@sbarrow-desktop> <200711190003.40228.larry@garfieldtech.com> <23.9D.31009.0A821474@pb1.pair.com> In-Reply-To: <23.9D.31009.0A821474@pb1.pair.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-ID: <200711190044.25638.larry@garfieldtech.com> Subject: Re: [PHP-DEV] Multiple class inheritance From: larry@garfieldtech.com (Larry Garfield) On Monday 19 November 2007, Edward Z. Yang wrote: > Larry Garfield wrote: > > It sounds like you want to be using decorators instead. > > The decorator pattern is inappropriate for this case, because Sam wants > to extend the interface, not change the behavior of an existing one. class AbstractField { // ... } class InputField { protected $field; function __construct($field) { $this->$field = $field; } function __call($method, $args) { return call_user_func_array(array($this->field, $method), $args); } // Other methods. } class DBField { protected $field; function __construct($field) { $this->$field = $field; } function __call($method, $args) { return call_user_func_array(array($this->field, $method), $args); } // Other methods. } $myfield = new InputField(new DBField(new AbstractField(...))); This is a case where you don't want type-hinting, actually. :-) You could do the same thing with an AbstractField interface that DBField and InputField also implement and pass through, which might be faster because you eliminate the _call()/call_user_func_array() choke point, but it's more code to write. Pick your poison. -- Larry Garfield AIM: LOLG42 larry@garfieldtech.com ICQ: 6817012 "If nature has made any one thing less susceptible than all others of exclusive property, it is the action of the thinking power called an idea, which an individual may exclusively possess as long as he keeps it to himself; but the moment it is divulged, it forces itself into the possession of every one, and the receiver cannot dispossess himself of it." -- Thomas Jefferson