Re: Use "caller" keyword, to access object caller.

From: Date: Sun, 01 Feb 2015 00:23:52 +0000
Subject: Re: Use "caller" keyword, to access object caller.
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-81506@lists.php.net to get a copy of this message
Hi! > If the caller explicitly send the object as an argument, it worsens > loose depending API. > > And agreed this code looks weird and not well thought-out: > <?php > > $holder->object->call($holder); This code explicitly says "object->call() is using $holder". It is clear and unambiguous. If you did it implicitly - i.e. wrote $holder->object->call() and that used $holder under the hood in call() - then you could have modified or even completely destroyed $holder under the assumption that nobody depends on it, but in fact whatever is in $holder->object, unknown to you, would depend on it and would break. Such hidden dependencies are not a good design. > But if have an easy way to get a pointer to the owner, in practice, is > very convenient. It may be convenient in short run, but I think in the long run creating hidden dependencies would make code less robust so it is better not to enable it as a best practice. -- Stas Malyshev smalyshev@gmail.com

« previous php.internals (#81506) next »