2013/3/19 Johannes Schlüter <johan...@schlueters.de> > > > "Matīss Roberts Treinis" <mrtrei...@gmail.com> wrote: > > >Proposal: > > > >Two additional magic methods for PHP objects - > > > >__refer(void): > > > >Refer method is called whenever object's identifier is assigned to > >variable, if such method is present. > >Example: > > > >$foo = new Bar; > >$bar = $foo; //__refer invoked > > This assignment is handled using PHP's copy on write mechanism for any > variable. A change here has massive impact on any variable assignment, > function parameter passing, ... and tons of internal places. > > What we have is a hook for the objects own reference counting which is > affected when an object refering to an object is used in write-context by > the engine, that might easily be exteded but is rather useless. (It's > trivial to create an interface or abstract base class providing this > addref/delref info) > > Unless you can provide a robust good patch without performance penalty in > cases where this isn't used this will lead nowhere, and I doubt there is a > way to come up with that. (rewriting the engine might be the closest > approach) > > johannes > > I doubt my ability to rewrite engine in reasonable amount of time. With that, I mean, lifespan of the universe at least.
However, as far as I understand, variables can currently hold values like arrays, strings, etc, and object references. Could it be possible to add one more possible value to this keen little list - like special type of reference? Therefore we could only take a special care only on those references which are known to be bound to objects which does posses __refer and __unrefer, therefore effect on rest of the variable operations could be brought to minimum and overhead would only affect those special objects. Also, a little overhead is reasonable for the new functionality. It is not like we have Pentium 2's in our DC's anymore.