Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:81400 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 70483 invoked from network); 30 Jan 2015 04:43:03 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Jan 2015 04:43:03 -0000 Authentication-Results: pb1.pair.com header.from=larry@garfieldtech.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=larry@garfieldtech.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain garfieldtech.com from 66.111.4.27 cause and error) X-PHP-List-Original-Sender: larry@garfieldtech.com X-Host-Fingerprint: 66.111.4.27 out3-smtp.messagingengine.com Received: from [66.111.4.27] ([66.111.4.27:54008] helo=out3-smtp.messagingengine.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 4C/04-47940-5DB0BC45 for ; Thu, 29 Jan 2015 23:43:01 -0500 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 4D8AA2063E for ; Thu, 29 Jan 2015 23:42:59 -0500 (EST) Received: from frontend2 ([10.202.2.161]) by compute6.internal (MEProxy); Thu, 29 Jan 2015 23:42:59 -0500 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=x-sasl-enc:message-id:date:from :mime-version:to:subject:references:in-reply-to:content-type :content-transfer-encoding; s=smtpout; bh=Bktx4yQSKCI2jTOIwgjmJG a8+JQ=; b=rl3UfBLSoc8uGRUZotXz9piSyy+bf0M2Orjew6REF97Lx7XQW59ryN Zmo2Cz+FmfUtGOJabLV8UD3xRLvjCeA5qxIB9oGYMinz5W/sqOfCcXPE70YJh5vN 62TNub6kHWOLJWmw0BPQ13UdCL8xop8bqvWEKc4S/1HnG41bFEqa8= X-Sasl-enc: tcEzC4wsKWYhdHIaZGvQ9gKHNpe4jriHdWT1AS/0HR8w 1422592979 Received: from [192.168.42.108] (unknown [98.226.241.18]) by mail.messagingengine.com (Postfix) with ESMTPA id 0C91E68008C for ; Thu, 29 Jan 2015 23:42:59 -0500 (EST) Message-ID: <54CB0BD4.8060402@garfieldtech.com> Date: Thu, 29 Jan 2015 22:43:00 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: internals@lists.php.net References: In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Use "caller" keyword, to access object caller. From: larry@garfieldtech.com (Larry Garfield) On 01/29/2015 10:30 PM, S.A.N wrote: > I will clarify the benefits of the keyword. > Single instance of the class can reused in different contexts calls. > > > class A > { > public $object; > } > > class B > { > public $object; > } > > class C > { > public function getCaller() { > return caller::class; > } > } > > $a = new A; > $b = new B; > $c = new C; > > $a->object = $c; > $b->object = $c; > > $a->object->getCaller(); // return A > $b->object->getCaller(); // return B > > $c->getCaller(); // Fatal Error - undefined caller context > > ?> This seems like an extremely bad idea to do in the first place. Code in class C should function the same whether it was called from $a or $b. If it should vary, that should be made explicit in the object's construction and you have DIFFERENT instances of it. Having an object that behaves differently depending on an implicit relationship with where it happened to be called from is full of all kinds of impossible to debug magic. I don't even know how you'd unit test it. I can think of no use case where this wouldn't cause only problems. --Larry Garfield