Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:27953 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 91589 invoked by uid 1010); 9 Feb 2007 17:16:04 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 91574 invoked from network); 9 Feb 2007 17:16:04 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Feb 2007 17:16:04 -0000 Authentication-Results: pb1.pair.com header.from=johannes@php.net; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=johannes@php.net; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain php.net from 82.135.72.163 cause and error) X-PHP-List-Original-Sender: johannes@php.net X-Host-Fingerprint: 82.135.72.163 ppp-82-135-72-163.dynamic.mnet-online.de Received: from [82.135.72.163] ([82.135.72.163:58291] helo=johannes.nop) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 2A/71-18147-25CACC54 for ; Fri, 09 Feb 2007 12:16:03 -0500 Received: from johannes.nop (localhost [127.0.0.1]) by johannes.nop (8.13.8/8.13.8) with ESMTP id l19HFrkd002953; Fri, 9 Feb 2007 18:15:53 +0100 Received: (from johannes@localhost) by johannes.nop (8.13.8/8.13.8/Submit) id l19HFruj002952; Fri, 9 Feb 2007 18:15:53 +0100 X-Authentication-Warning: johannes.nop: johannes set sender to johannes@php.net using -f To: Jim Wilson Cc: internals@lists.php.net In-Reply-To: References: Content-Type: text/plain Content-Transfer-Encoding: 7bit Date: Fri, 09 Feb 2007 18:15:52 +0100 Message-ID: <1171041352.10873.578.camel@johannes.nop> Mime-Version: 1.0 X-Mailer: Evolution 2.8.2.1 (2.8.2.1-3.fc6) Subject: Re: [PHP-DEV] Reflection API Injection Mechanism From: johannes@php.net (Johannes =?ISO-8859-1?Q?Schl=FCter?=) Hi Jim, you're searching for runkit ;-) http://de.php.net/manual/en/ref.runkit.php johannes On Fri, 2007-02-09 at 10:18 -0600, Jim Wilson wrote: > Dear PHP Internals subscribers, > > I have two quick questions regarding PHP 5's Reflection API (I apologize if > this isn't the right list to ask): > > 1) Is there a way to inject a method into a Class such that future > instantiations of that Class will have the method? For example: > > ------------ Before ----------- > class A { > // Nothing > } > ------------ Before ----------- > > ------------ After ----------- > class A { > // method which was injected > public function injectedFunc($someArg) { > // .... > } > } > ------------ After ----------- > > Obviously I'm not looking for a way to modify class A's source code, just > the effective class A specification. > > I know that PHP supports extending classes and interfaces, but in my > use-case that isn't really an option since I don't control the code which > instantiates the objects, and they're not using any kind of Factory pattern > for object construction that I could overload with my extended > implementation. > > 2) Is there a way to change a method which already exists, as in by > overwriting it with a new function? I'm looking to do the equivalent of > JavaScript's 'function as member' treatment, where it's easy to do something > like: > > ------------ Snip ----------- > // Obj is some object > Obj.meth = function (arg) { /* do something with arg */ }; > > // Then later on ... > Obj.meth('hello there'); > ------------ Snip ----------- > > Thanks in advance for any help, or for redirecting me to the correct list if > this isn't it. > > -- Jim R. Wilson