Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:81438 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 81797 invoked from network); 30 Jan 2015 16:43:40 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Jan 2015 16:43:40 -0000 Authentication-Results: pb1.pair.com header.from=tyra3l@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=tyra3l@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.47 as permitted sender) X-PHP-List-Original-Sender: tyra3l@gmail.com X-Host-Fingerprint: 74.125.82.47 mail-wg0-f47.google.com Received: from [74.125.82.47] ([74.125.82.47:38825] helo=mail-wg0-f47.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F0/B8-35409-8B4BBC45 for ; Fri, 30 Jan 2015 11:43:37 -0500 Received: by mail-wg0-f47.google.com with SMTP id n12so27932061wgh.6 for ; Fri, 30 Jan 2015 08:43:34 -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=gNou0RrJ+lAJamLxTnqvSQHeBVXzHs+rlLxG8VXQnqU=; b=RtrywBXDhv97WHdnNd/x0LZBvIxvORZ8x6BVrfJ98xUNMz93i5phgoXAVgMf94DF0O MMrsEN7mrX7MY6uqclYMiRAS6YtJQY5IFQqi1CNlAFkx4p71zVYLgk+lv/iGsxOvUE2V EZ+fcMVS0WZqqKOw4oVbY/raWdvJjEzgnc+RoeIZsj2wrYxOSLWswVlD+zYu863Z91BG Ag6+RYm+VZxP1GEx9NHrCk0N+askDFz64s5wbr8AdDZNmAviZw/96EGk8XKZjJM6JmCY bexXNXyvx0hoHmmgYYquZStiC0he0VOw23TjkraCsn5Brja1Vdf6g29OyfluVq1WDlz3 2bOw== MIME-Version: 1.0 X-Received: by 10.180.74.52 with SMTP id q20mr6640416wiv.0.1422636213888; Fri, 30 Jan 2015 08:43:33 -0800 (PST) Received: by 10.180.88.33 with HTTP; Fri, 30 Jan 2015 08:43:33 -0800 (PST) In-Reply-To: References: Date: Fri, 30 Jan 2015 17:43:33 +0100 Message-ID: To: "S.A.N" Cc: internals Content-Type: multipart/alternative; boundary=f46d043890792c6c9d050de14e56 Subject: Re: [PHP-DEV] Use "caller" keyword, to access object caller. From: tyra3l@gmail.com (Ferenc Kovacs) --f46d043890792c6c9d050de14e56 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Fri, Jan 30, 2015 at 3:53 AM, 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 t= o > 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 =3D new C; > } > } > > class B > { > public function __construct() { > $this->object =3D new C; > } > } > > class C > { > public function getCaller() { > return caller::class; > } > } > > $a =3D new A; > $b =3D new B; > $c =3D 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. > see the previous discussion on this topic: http://grokbase.com/t/php/php-internals/099g86x7k6/reference-caller-object I think having it as a magic constant would be better, but I still don't like the idea (it is already possible, there aren't really a good usecase for it, the example you mentioned is a prime example how would it be misused to cause debugging nightmares, etc.). --=20 Ferenc Kov=C3=A1cs @Tyr43l - http://tyrael.hu --f46d043890792c6c9d050de14e56--