Re: Use "caller" keyword, to access object caller.
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
[email protected]
Thread (19 messages)