Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:81497 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 53010 invoked from network); 31 Jan 2015 19:41:18 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 31 Jan 2015 19:41:18 -0000 Authentication-Results: pb1.pair.com header.from=ua.san.alex@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ua.san.alex@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.213.171 as permitted sender) X-PHP-List-Original-Sender: ua.san.alex@gmail.com X-Host-Fingerprint: 209.85.213.171 mail-ig0-f171.google.com Received: from [209.85.213.171] ([209.85.213.171:61719] helo=mail-ig0-f171.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 2C/F1-39884-DDF2DC45 for ; Sat, 31 Jan 2015 14:41:18 -0500 Received: by mail-ig0-f171.google.com with SMTP id r10so10360705igi.4 for ; Sat, 31 Jan 2015 11:41:15 -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:content-transfer-encoding; bh=xVsxkZLFPc9sXJZDk+VjehX4CWcA5D8PGcWG1+JkJHI=; b=NUJGssQmoHdtDTaAvcQRfEloLZS540rZs52paDjqO/Hrywzn45rbEN5fV/1WCt6gL1 U5Kkvnu/8j/t4BlEveLlck9Uk+yeDl3gS+tWeIMbW6Kd8A/7BFvnuMn7Y5xsELtsIfay xQx2YXsIMBKVb+ZP2ij7O8iuQBREsWRrnSnJ+UXJCoKTxM0MI8+0bGu7hYgPWDzc9pva ePwAkdb1ZKWhGPuFddyX8n3qJVuF3/4YvXGZh/grKcun0fAC9UfW0+zIr9lotFL8gJ1M DrXGu8o2Pen6H+sHqUOPdZ8BcvYboy8H3+AiXTIxDAUfqevTkHPiMVkhbi+Mcu0wpY2Y 0v3g== MIME-Version: 1.0 X-Received: by 10.42.222.68 with SMTP id if4mr5488581icb.45.1422733274965; Sat, 31 Jan 2015 11:41:14 -0800 (PST) Received: by 10.50.93.3 with HTTP; Sat, 31 Jan 2015 11:41:14 -0800 (PST) In-Reply-To: References: Date: Sat, 31 Jan 2015 21:41:14 +0200 Message-ID: To: Ferenc Kovacs Cc: internals Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Use "caller" keyword, to access object caller. From: ua.san.alex@gmail.com ("S.A.N") No, I'm not describing this behavior, but I chose the wrong name keyword, this is not perceived correctly. My source code examples, it is clear that no returns previous object from the call stack, me need return references to the holder object. It's more like the dynamic of "this" in JavaScript. Dynamic "this", sometimes very convenient for the event model, so I proposed to implement this feature in PHP. In PHP, there traits, extends, but it's all static bind, in runtime can not be added or redefined. I'll show a simple JS example, in which needed behavior dynamic this. Perhaps we should use the keyword "this" instead of "caller"? :) Then the code in PHP will look like this: object =3D $c; $b->object =3D $c; $a->object->getHolder(); // return A $b->object->getHolder(); // return B $c->getHolder(); // Fatal Error - undefined context ?> What do you think? Thank. 2015-01-30 18:43 GMT+02:00 Ferenc Kovacs : > > > 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 = 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 =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-objec= t > 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 misu= sed > to cause debugging nightmares, etc.). > > -- > Ferenc Kov=C3=A1cs > @Tyr43l - http://tyrael.hu