Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:64947 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 41331 invoked from network); 14 Jan 2013 19:53:43 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Jan 2013 19:53:43 -0000 Authentication-Results: pb1.pair.com header.from=sebastian.krebs.berlin@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=krebs.seb@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.175 as permitted sender) X-PHP-List-Original-Sender: krebs.seb@gmail.com X-Host-Fingerprint: 209.85.212.175 mail-wi0-f175.google.com Received: from [209.85.212.175] ([209.85.212.175:36341] helo=mail-wi0-f175.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CF/88-22727-54264F05 for ; Mon, 14 Jan 2013 14:53:42 -0500 Received: by mail-wi0-f175.google.com with SMTP id hm11so1577153wib.14 for ; Mon, 14 Jan 2013 11:53:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:x-google-sender-delegation:in-reply-to :references:date:x-google-sender-auth:message-id:subject:from:to:cc :content-type; bh=1GHgxXnBvnV58/SAxYfyAwe06NqkzWYxXhHCWGuI0rM=; b=pFodXRSK7gDsIOGMvPHVDslO12Utb7jDT/4V8g1wVt3qFp0krmAEDSAnEryerxsEL+ YHTqDaRGvbU2g7tefa7e3e70tNrh0GLh9Isy6L92cO42PKkE0rTHFzk+y56QZq0iew1N SyNzLjsNkMcUu0WW2U/d7qthpj02fb1zi39wx9750hJbE3MHlEH+pqW0DtsPsYaJ4RSr G9JkgrAjSsj9ltIcMZraoL2tHfoqutcJ+ds7ridy/O7eRijz8zgPDdb6uQvkV1RDvkGE mKguDxivplP/DX2AXPnEhXaAebSLo8BdSa8dm2LnWs0jcmvWWP3oeKhSJhSQRrhTKG87 GETA== MIME-Version: 1.0 Received: by 10.194.179.34 with SMTP id dd2mr137423040wjc.1.1358193219027; Mon, 14 Jan 2013 11:53:39 -0800 (PST) Sender: sebastian.krebs.berlin@gmail.com X-Google-Sender-Delegation: sebastian.krebs.berlin@gmail.com Received: by 10.216.119.70 with HTTP; Mon, 14 Jan 2013 11:53:38 -0800 (PST) In-Reply-To: References: Date: Mon, 14 Jan 2013 20:53:38 +0100 X-Google-Sender-Auth: eJsKw6ZqV5zJM4uDSEw9AOCKsao Message-ID: To: Alexander Lissachenko Cc: PHP internals list Content-Type: multipart/alternative; boundary=089e0141a0025b40ff04d345003d Subject: Re: [PHP-DEV] [Reflection] Improve logic of ReflectionMethod->invokeArgs() for static methods From: krebs.seb@gmail.com (Sebastian Krebs) --089e0141a0025b40ff04d345003d Content-Type: text/plain; charset=ISO-8859-1 2013/1/14 Alexander Lissachenko > My use-case is weaving aspects into the methods. Yeah! ) > > So, I take the original class, rename it and then create a decorator > class instead of original class with overridden dynamic and static > methods. Method in the decorator should make some specific logic and > then just invokes the original static method with Reflection, but the > scope should be also correct. > > For example, previous class First will be renamed during load-time to > the First_AopProxied: > > class First_AopProxied > { > public static function foo() > { > echo get_called_class(); > } > } > > and decorator will be created > > class First extends First_AopProxied > { > public static function foo() > { > // some logic here, that should call parent method and > preserve the scope (class First) > // can not use parent::foo() here, because around advice > should be able to call this method somewhere in the closure... > } > } > I must say this example is not really better than the last one (it feels like it is exactly the same with 2 lines more comments). Also I don't know, what you mean by "call this method somewhere in the closure"; which closure?!? I guess you are in fact looking for regular instance methods. > > 2013/1/14 Sebastian Krebs : > > > > > > > > 2013/1/14 Alexander Lissachenko > >> > >> Hi! It's my first letter here ) > >> > >> I want to suggest a small improvement for ReflectionMethod->invoke() > >> and ReflectionMethod->invokeArgs() methods to support LSB for > >> overridden static methods. Currently, for invoking static methods > >> first argument should be null, information about class (scope) is > >> taken from the reflection class. However, there is one issue that can > >> not be solved at the current time. > >> > >> Suppose, we have two classes: > >> > >> class First > >> { > >> public static function foo() > >> { > >> echo get_called_class(); > >> } > >> } > >> > >> class Second extends First > >> { > >> public static function foo() > >> { > >> echo "Do not call me, please"; > >> } > >> } > >> > >> Now I want to invoke the First::foo() method with Reflection from the > >> Second class scope for using LSB. Currently this is impossible: > >> $class = new ReflectionClass('First'); > >> $class->getMethod('foo')->invokeArgs(null, array()); // Outputs > >> 'First' as no scope information is passed > >> > >> > >> $class = new ReflectionClass('Second'); > >> $class->getMethod('foo')->invokeArgs(null, array()); // Outputs 'Do > >> not call me, please' as method is redefined > >> > >> So, there is no way now to invoke the static First::foo() method from > >> the child scope because it was redefined. However, this can be easily > >> implemented by adding the scope for static methods invocation (like > >> Closure::bindTo()): > >> > >> $class = new ReflectionClass('First'); > >> $class->getMethod('foo')->invokeArgs('Second', array()); // Outputs > >> 'Second' > >> > >> This improvement can be very useful for building proxies for static > >> methods, that use LSB. Can it be implemented for PHP 5.3-5.5? Thanks! > > > > > > Maybe it's just me, but could you explain which use-case want to solve? > The > > example isn't very useful, because you can achieve this quite easy > without > > reflection. Also why do you override the method, when you don't want it > to > > get called? Shouldn't they two separate methods then? > > > > > class First > > { > > public static function foo() > > { > > echo get_called_class(); > > } > > } > > > > class Second extends First > > { > > public static function foo() > > { > > echo "Do not call me, please"; > > } > > public static function bar() { > > parent::foo(); > > } > > } > > Second::bar(); > > > > http://codepad.viper-7.com/fwG5GB > > > >> > >> > >> -- > >> PHP Internals - PHP Runtime Development Mailing List > >> To unsubscribe, visit: http://www.php.net/unsub.php > >> > > > > > > > > -- > > github.com/KingCrunch > -- github.com/KingCrunch --089e0141a0025b40ff04d345003d--