Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:81524 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 67838 invoked from network); 1 Feb 2015 09:29:32 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Feb 2015 09:29:32 -0000 Authentication-Results: pb1.pair.com header.from=php@bof.de; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=php@bof.de; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain bof.de designates 80.242.145.70 as permitted sender) X-PHP-List-Original-Sender: php@bof.de X-Host-Fingerprint: 80.242.145.70 mars.intermailgate.com Received: from [80.242.145.70] ([80.242.145.70:32891] helo=mars.intermailgate.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 9D/73-01632-BF1FDC45 for ; Sun, 01 Feb 2015 04:29:31 -0500 Received: (qmail 979 invoked by uid 1009); 1 Feb 2015 10:29:28 +0100 Received: from 209.85.216.48 by mars (envelope-from , uid 89) with qmail-scanner-1.25-st-qms (clamdscan: 0.96.2/20012. spamassassin: 3.3.1. perlscan: 1.25-st-qms. Clear:RC:1(209.85.216.48):. Processed in 0.267233 secs); 01 Feb 2015 09:29:28 -0000 X-Antivirus-MYDOMAIN-Mail-From: php@bof.de via mars X-Antivirus-MYDOMAIN: 1.25-st-qms (Clear:RC:1(209.85.216.48):. Processed in 0.267233 secs Process 971) Received: from mail-qa0-f48.google.com (gmail@bof.de@209.85.216.48) by mars.intermailgate.com with RC4-SHA encrypted SMTP; 1 Feb 2015 10:29:28 +0100 Received: by mail-qa0-f48.google.com with SMTP id v8so25511161qal.7 for ; Sun, 01 Feb 2015 01:29:26 -0800 (PST) MIME-Version: 1.0 X-Received: by 10.224.134.202 with SMTP id k10mr30580306qat.32.1422782966412; Sun, 01 Feb 2015 01:29:26 -0800 (PST) Received: by 10.140.94.104 with HTTP; Sun, 1 Feb 2015 01:29:26 -0800 (PST) Received: by 10.140.94.104 with HTTP; Sun, 1 Feb 2015 01:29:26 -0800 (PST) In-Reply-To: References: <54CD6AD6.9080209@gmail.com> Date: Sun, 1 Feb 2015 10:29:26 +0100 Message-ID: To: "S.A.N" Cc: internals , Stas Malyshev Content-Type: multipart/alternative; boundary=047d7b6740b24e3b49050e03794e Subject: Re: [PHP-DEV] Use "caller" keyword, to access object caller. From: php@bof.de (Patrick Schaaf) --047d7b6740b24e3b49050e03794e Content-Type: text/plain; charset=UTF-8 Am 01.02.2015 01:15 schrieb "S.A.N" : > > $holder->object->call($holder); The way I solve this in the very few places (*) where it makes sense, is to use __call in the holder class to implement forwarding methods that pass on the holder object reference. The member property is NOT exposed. Call will be like this: $holder->object_call(); Code could look something like this (untested): class holder { public function __call($method, $args) { list ($propname, $membermethod) = explode('_', $method, 2); if (!property_exists($this->$propname) || !is_object($this->$propname)) // add other policy return null; // or any other error behaviour return $this->$propname->$membermethod($this, ...$args); } } (*) really just one place at the moment, tightly coupled, and not as general as shown above. I don't see a use for the fully general case, where the member objects would both care about knowing their holder object _and_ work with practically any holder object. best regards Patrick --047d7b6740b24e3b49050e03794e--