Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:81397 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 64628 invoked from network); 30 Jan 2015 03:50:56 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Jan 2015 03:50:56 -0000 Authentication-Results: pb1.pair.com header.from=jrbasso@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=jrbasso@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.223.176 as permitted sender) X-PHP-List-Original-Sender: jrbasso@gmail.com X-Host-Fingerprint: 209.85.223.176 mail-ie0-f176.google.com Received: from [209.85.223.176] ([209.85.223.176:45154] helo=mail-ie0-f176.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A0/F2-47940-F9FFAC45 for ; Thu, 29 Jan 2015 22:50:56 -0500 Received: by mail-ie0-f176.google.com with SMTP id at20so913787iec.7 for ; Thu, 29 Jan 2015 19:50:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=fNeT83J3n0C+zT69Pqbuuvaz+iMluhwMu7SFRkpMb0M=; b=mV6kdlb6YSXWW5rIOElIvYsrJExO4FtsBLNWFuvpLM8fRjBYGpXUwFOPJhJhjaMSLf ZnT0lJuRcqb5HLYRaT4zSIeksVu8wcBoy8LSo/6hQ/tgPocahqfjZMC+wGSNkTgRTaca E89/ndHFUFVDdxe8yGCWnlI+VrOpUN8CSd3A//BKD8LPQhLucA01jY1BIr7+kaK+fcmt bXrnBCkVQjHLUaN0Kao6YWF7fguH/MRdNmCzs0OVOlHsdqX8uxHye90PoQ1mR6PiZGXO WBzxQL5nVkIp8SsMUg+lv+RIJY/n7HWQYEH5RHx+z09fC1EBkSp6PbSvDqMQyfVbpvGk lMhQ== MIME-Version: 1.0 X-Received: by 10.43.126.67 with SMTP id gv3mr4227706icc.31.1422589853152; Thu, 29 Jan 2015 19:50:53 -0800 (PST) Received: by 10.64.25.114 with HTTP; Thu, 29 Jan 2015 19:50:53 -0800 (PST) In-Reply-To: References: Date: Thu, 29 Jan 2015 22:50:53 -0500 Message-ID: To: "S.A.N" Cc: internals Content-Type: multipart/alternative; boundary=bcaec51824a8dbbd71050dd68291 Subject: Re: [PHP-DEV] Use "caller" keyword, to access object caller. From: jrbasso@gmail.com (Juan Basso) --bcaec51824a8dbbd71050dd68291 Content-Type: text/plain; charset=UTF-8 Usually it is solved sending the $this instance to class C constructor and C object storing it in some attribute, solving the problem. I don't think a new keyword would help. Juan Basso On Thu, Jan 29, 2015 at 9:53 PM, S.A.N wrote: > The reason for creating circular references, usually due to the need to > bind objects. > > But this relationship can often be obtained from the context of the call. > > It will be very convenient to have a keyword that will return reference to > an object, which caused this object. > > Sorry for my English, I'm not a native speaker. > A simple example below shows the behavior that we need. > > > class A > { > public function __construct() { > $this->object = new C; > } > } > > class B > { > public function __construct() { > $this->object = new C; > } > } > > class C > { > public function getCaller() { > return caller::class; > } > } > > $a = new A; > $b = new B; > $c = new C; > > $a->object->getCaller(); // return A > $b->object->getCaller(); // return B > > $c->getCaller(); // Fatal Error - undefined caller context > > ?> > > Create a new keyword can cause problems with backward compatibility... > Perhaps you can solve a problem to using an existing keyword? > > Thank you for any feedback. > --bcaec51824a8dbbd71050dd68291--