Re: Proposal: new magic methods for Object references.
| From: | Johannes Schlüter | Date: | Tue, 19 Mar 2013 20:43:03 +0000 |
| Subject: | Re: Proposal: new magic methods for Object references. | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-66708@lists.php.net to get a copy of this message | ||
"Matīss Roberts Treinis" <mrtreinis@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