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

From: Date: Sun, 01 Feb 2015 00:40:06 +0000
Subject: Re: Use "caller" keyword, to access object caller.
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-81507@lists.php.net to get a copy of this message
2015-02-01 2:23 GMT+02:00 Stanislav Malyshev <smalyshev@gmail.com>: > 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 Everything is relative, when there is an experience in a dynamic context (this) in JS, while unwieldy structure in PHP code look something old and not comfortable. I think, that purchased experience will be the use of safety culture dynamic runtime context, many developers it would be appreciated, to implement this PHP frameworks.

« previous php.internals (#81507) next »