Re: constructor hook
| From: | Ralph Schindler | Date: | Tue, 18 Sep 2012 17:10:35 +0000 |
| Subject: | Re: constructor hook | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-63075@lists.php.net to get a copy of this message | ||
This is one of the main use cases of AOP. Demonstrated by this script:
<?php
class Bar {}
class Foo {
public function __construct(Bar $b) {
echo 'instance of ' . get_class($b);
}
}
function doDi($joinpoint) {
// do smart stuff, then call:
$joinpoint->setArguments(array(new Bar));
}
aop_add_before('Foo->__construct()', 'doDi');
$f = new Foo; // 'instance of Bar'-ralph On 9/18/12 11:22 AM, jpauli wrote:
On Tue, Sep 18, 2012 at 5:14 PM, Amaury Bouchard <amaury@amaury.net> wrote:Sounds to me like aspect-oriented programming, applied to object construction. Take a look at: https://github.com/AOP-PHP/AOP+1, this is the same case as AOP, but for constructor. Thus AOP may fit the need. Julien.P