Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:52503 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 21946 invoked from network); 23 May 2011 02:49:16 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 May 2011 02:49:16 -0000 Authentication-Results: pb1.pair.com header.from=drak@zikula.org; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=drak@zikula.org; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zikula.org designates 74.125.82.170 as permitted sender) X-PHP-List-Original-Sender: drak@zikula.org X-Host-Fingerprint: 74.125.82.170 mail-wy0-f170.google.com Received: from [74.125.82.170] ([74.125.82.170:56561] helo=mail-wy0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CC/04-23260-B2BC9DD4 for ; Sun, 22 May 2011 22:49:16 -0400 Received: by wyb34 with SMTP id 34so4358466wyb.29 for ; Sun, 22 May 2011 19:49:13 -0700 (PDT) Received: by 10.216.122.10 with SMTP id s10mr1783640weh.34.1306118953057; Sun, 22 May 2011 19:49:13 -0700 (PDT) MIME-Version: 1.0 Received: by 10.216.51.72 with HTTP; Sun, 22 May 2011 19:48:53 -0700 (PDT) Date: Mon, 23 May 2011 08:33:53 +0545 Message-ID: To: internals@lists.php.net Content-Type: text/plain; charset=UTF-8 Subject: call_user_func performance and dynamic code From: drak@zikula.org (Drak) I'd like to ask a question about call_user_func/_array performance and the use of runtime variables to call functions and methods from the PHP internals perspective. Many people have blogged about how:- $callable = array($object, $bar); call_user_func_array($callable, $args); is considerably slower than $object->$bar($args); and there seem to be plenty benchmarks to back this up. What is the official standpoint from the PHP developers and is there are reason to use call_user_func/_array over using variables to express the call when considering opcode caching? What I mean for example, is, when using $foo->$bar($args) at runtime, maybe this is faster than call_user_func but maybe not if an opcode cache is involved (e.g. maybe it cannot cache $foo). I ask this because things like __call() and __get() are also notoriously slow. Also, would there be a reason for certain dynamic notations to be slower than others (again with and without opcode caching incolved) - a few examples below: $foo(); $foo->$bar(); $array[0]->$array[1]; $foo::bar(); $array[0]::$array[1](); PHP has evolved a lot over the years so it would be nice to know what the intention, pros and cons of these methodologies are from an official internals point of view and if anything has been changed to over time to make these methodologies more efficient. Regards, Drak