Re: Use "caller" keyword, to access object caller.
| From: | Ferenc Kovacs | Date: | Fri, 30 Jan 2015 16:43:33 +0000 |
| Subject: | Re: Use "caller" keyword, to access object caller. | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-81438@lists.php.net to get a copy of this message | ||
On Fri, Jan 30, 2015 at 3:53 AM, S.A.N <ua.san.alex@gmail.com> 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.
>
> <?php
>
> 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.
>
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.).
--
Ferenc Kovács
@Tyr43l - http://tyrael.hu