Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:81399 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 68673 invoked from network); 30 Jan 2015 04:30:30 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Jan 2015 04:30:30 -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.176 as permitted sender) X-PHP-List-Original-Sender: ua.san.alex@gmail.com X-Host-Fingerprint: 209.85.213.176 mail-ig0-f176.google.com Received: from [209.85.213.176] ([209.85.213.176:51125] helo=mail-ig0-f176.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id EE/A3-47940-5E80BC45 for ; Thu, 29 Jan 2015 23:30:29 -0500 Received: by mail-ig0-f176.google.com with SMTP id hl2so652981igb.3 for ; Thu, 29 Jan 2015 20:30:27 -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=ELG9IUh9kWGDR5DrneDh/fCcf6pwRFZ5QSClI7F5OC0=; b=Ms/QcoIBYrTvFfZJW5F4fuNjvk62F99O+eN0LmzzF+WbAdSC7HD8Yv+T88RN8el+gc 3cqT639MlrDBG2QDLOEN4Ov2urw/pQoiQYoSIki4Oji18CFt82HN4Ipty+wYYYmwLrfh SeyQ25xX9cOVDocoIpENI6pzUPLZ6p/6u9OTu9kpoVktxC3VL5N0dT3kePqK6e1qgO7O o5cwwb2nCyXAI8E8fRSGCIIuu16n19nOgXtUaUBH8xFcHW9440xfvzrN6FvIRyBileZ/ OWD04YBAdiYmjhJVmIdloGibfNLmqc5IvwC0HVpZTFtGTClu8TD4jbsluUAOEAENGRop YDLw== MIME-Version: 1.0 X-Received: by 10.107.37.71 with SMTP id l68mr4931331iol.64.1422592227000; Thu, 29 Jan 2015 20:30:27 -0800 (PST) Received: by 10.50.93.3 with HTTP; Thu, 29 Jan 2015 20:30:26 -0800 (PST) In-Reply-To: References: Date: Fri, 30 Jan 2015 06:30:26 +0200 Message-ID: To: Juan Basso Cc: internals Content-Type: multipart/alternative; boundary=001a1140ee2c59ca19050dd71020 Subject: Re: [PHP-DEV] Use "caller" keyword, to access object caller. From: ua.san.alex@gmail.com ("S.A.N") --001a1140ee2c59ca19050dd71020 Content-Type: text/plain; charset=UTF-8 I will clarify the benefits of the keyword. Single instance of the class can reused in different contexts calls. object = $c; $b->object = $c; $a->object->getCaller(); // return A $b->object->getCaller(); // return B $c->getCaller(); // Fatal Error - undefined caller context ?> 2015-01-30 5:50 GMT+02:00 Juan Basso : > 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. >> > > --001a1140ee2c59ca19050dd71020--