Hi,

  public function foo()
  {
      $bar    = new Bar;
[...]
  }

When I want to test the foo() method, I want to stub out the usage of
the Bar class, for example, and have Bar::doSomething() return a
pre-configured value instead of performing its normal operation.

This is where you'd start refactoring the above sourcecode. I don't like this idea at all, because it really only helps you with testing legacy source you might not be able to or do not want to change (want to say: rare use-case IMO).

If you really need to intercept construction, you can still weave your interception functionality into sourcecode as you'd be doing in any AOP library. Simply write a stream wrapper for the file:// stream or add a filter to it to intercept all includes and / or requires your legacy code might contain and rewrite the sourcecode while loading, replacing "new Foo" by "newinstance('Foo')" - this might even be possible in a safe manner by using preg_replace.

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

Reply via email to