Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:27946 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 39699 invoked by uid 1010); 9 Feb 2007 16:18:16 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 39675 invoked from network); 9 Feb 2007 16:18:15 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Feb 2007 16:18:15 -0000 Authentication-Results: pb1.pair.com smtp.mail=wilson.jim.r@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=wilson.jim.r@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 66.249.92.170 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: wilson.jim.r@gmail.com X-Host-Fingerprint: 66.249.92.170 ug-out-1314.google.com Linux 2.4/2.6 Received: from [66.249.92.170] ([66.249.92.170:10267] helo=ug-out-1314.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 53/48-18147-2CE9CC54 for ; Fri, 09 Feb 2007 11:18:14 -0500 Received: by ug-out-1314.google.com with SMTP id o4so832528uge for ; Fri, 09 Feb 2007 08:18:03 -0800 (PST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:mime-version:content-type; b=U6wb42TcZHG0rwIKzJfP8UVPHunf7jVjWWgoRbx065EsquxqmIeK+Sc/Z2UBpbPs+hpunTRBySGjf4OsCwnoTrmRQjEGbH/SWLiGHD6yn79mOUyt0KqCv/DEDBybOZOVRcjKiRPqP4ZqsclJmUQQlbYLGTdBEvjgkFeYrQuKms0= Received: by 10.66.244.10 with SMTP id r10mr11412547ugh.1171037883073; Fri, 09 Feb 2007 08:18:03 -0800 (PST) Received: by 10.66.218.2 with HTTP; Fri, 9 Feb 2007 08:18:03 -0800 (PST) Message-ID: Date: Fri, 9 Feb 2007 10:18:03 -0600 To: internals@lists.php.net MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_34559_29019372.1171037883034" Subject: Reflection API Injection Mechanism From: wilson.jim.r@gmail.com ("Jim Wilson") ------=_Part_34559_29019372.1171037883034 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline 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 ------=_Part_34559_29019372.1171037883034--