Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:64944 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 35328 invoked from network); 14 Jan 2013 19:24:29 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Jan 2013 19:24:29 -0000 Authentication-Results: pb1.pair.com smtp.mail=krebs.seb@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=sebastian.krebs.berlin@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.52 as permitted sender) X-PHP-List-Original-Sender: krebs.seb@gmail.com X-Host-Fingerprint: 74.125.82.52 mail-wg0-f52.google.com Received: from [74.125.82.52] ([74.125.82.52:42839] helo=mail-wg0-f52.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 47/77-22727-B6B54F05 for ; Mon, 14 Jan 2013 14:24:29 -0500 Received: by mail-wg0-f52.google.com with SMTP id 12so2244669wgh.19 for ; Mon, 14 Jan 2013 11:24:25 -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=8Sh4978VzJjp4TY+gZy5eB8PGGtyBl9TNPZibSn2SRw=; b=y+vioydZkp64zZcGOvbXRDFvxpCA8JrhYHHPnlX79lXiZ10khxybHXDjInKsD+RMXw k8EJSsI6H3pWEg5yyPv7WNKo91twihLkMy9LWxeItBV95glrnXFrtJl8agTToHaHDIiT k7YdQK+eWVTOGY8xrey3jgsgXkCcPriv6ajRHG3HckVdhVSjH89yMEYPPdjp87BAWXW/ 7ZTCtTlrCqOC6iFjQp7/LyS8duoUZuhvQr9OhnoclYLEi1B3P7sOj0EMD846a0VDuytX LVV8sHIuntIJvgmgz9yUEipfC4CwMTUkYZJ2n6fHvhUASpZvKjRBlNSmZPWQRGl3wWxz CkCA== MIME-Version: 1.0 Received: by 10.180.88.40 with SMTP id bd8mr14203635wib.33.1358191465396; Mon, 14 Jan 2013 11:24:25 -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:24:25 -0800 (PST) In-Reply-To: References: Date: Mon, 14 Jan 2013 20:24:25 +0100 X-Google-Sender-Auth: KXfmcHOKJ-t6UbrsgM4Ku9gyy5Y Message-ID: To: Alexander Lissachenko Cc: PHP internals list Content-Type: multipart/alternative; boundary=f46d04428f12d4fa4a04d34497a7 Subject: Re: [PHP-DEV] [Reflection] Improve logic of ReflectionMethod->invokeArgs() for static methods From: krebs.seb@gmail.com (Sebastian Krebs) --f46d04428f12d4fa4a04d34497a7 Content-Type: text/plain; charset=ISO-8859-1 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? > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > -- github.com/KingCrunch --f46d04428f12d4fa4a04d34497a7--