Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:32629 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 56494 invoked by uid 1010); 4 Oct 2007 08:27:37 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 56479 invoked from network); 4 Oct 2007 08:27:37 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Oct 2007 08:27:37 -0000 Authentication-Results: pb1.pair.com smtp.mail=thekid@thekid.de; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=thekid@thekid.de; sender-id=unknown Received-SPF: error (pb1.pair.com: domain thekid.de from 212.227.126.171 cause and error) X-PHP-List-Original-Sender: thekid@thekid.de X-Host-Fingerprint: 212.227.126.171 moutng.kundenserver.de Received: from [212.227.126.171] ([212.227.126.171:63130] helo=moutng.kundenserver.de) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id FE/81-45404-7F3A4074 for ; Thu, 04 Oct 2007 04:27:36 -0400 Received: from [89.15.97.107] (helo=unterwegs) by mrelayeu.kundenserver.de (node=mrelayeu0) with ESMTP (Nemesis) id 0MKwh2-1IdM3Q0BEF-0000vU; Thu, 04 Oct 2007 10:27:32 +0200 Message-ID: <015801c80660$64613b60$16b2a8c0@unterwegs> To: References: <4702777C.2090406@zend.com> <47027B78.5070909@sebastian-bergmann.de> Date: Thu, 4 Oct 2007 10:27:21 +0200 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="ISO-8859-15"; reply-type=original Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.3138 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3138 X-Provags-ID: V01U2FsdGVkX18xtkq+zqPySUX8W8kJe/qlBxE9WRY4+HqN3H2 4h3lK+AR0TOP1qlT1UjCJ86Jk4PhKX45hA+beLqOj0FNliojCj pQLNpasZU4DkkE30gRBuxcH04rIKH56 Subject: Re: [PHP-DEV] Class Posing From: thekid@thekid.de ("Timm Friebe") 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