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 <ama...@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



--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to