Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:76685 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 55792 invoked from network); 19 Aug 2014 08:55:27 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Aug 2014 08:55:27 -0000 Authentication-Results: pb1.pair.com header.from=derick@php.net; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=derick@php.net; spf=unknown; sender-id=unknown Received-SPF: unknown (pb1.pair.com: domain php.net does not designate 82.113.146.227 as permitted sender) X-PHP-List-Original-Sender: derick@php.net X-Host-Fingerprint: 82.113.146.227 xdebug.org Linux 2.6 Received: from [82.113.146.227] ([82.113.146.227:50883] helo=xdebug.org) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 23/00-55441-DF013F35 for ; Tue, 19 Aug 2014 04:55:26 -0400 Received: from localhost (localhost [IPv6:::1]) by xdebug.org (Postfix) with ESMTPS id 2620A10C054; Tue, 19 Aug 2014 09:55:20 +0100 (BST) Date: Tue, 19 Aug 2014 09:55:20 +0100 (BST) X-X-Sender: derick@whisky.home.derickrethans.nl To: Wei Dai cc: Aaron Lewis , PHP Internals In-Reply-To: <35D406B0A53A43FEAF472D9FC8371187@gmail.com> Message-ID: References: <86EEE03317124B84B62883DBE41C4ADD@gmail.com> <35D406B0A53A43FEAF472D9FC8371187@gmail.com> User-Agent: Alpine 2.11 (DEB 23 2013-08-11) MIME-Version: 1.0 Content-Type: MULTIPART/MIXED; BOUNDARY="8323329-1542724339-1408438521=:4107" Subject: =?UTF-8?Q?Re=3A_=E5=9B=9E=E5=A4=8D=EF=BC=9A_=5BPHP-DEV=5D_=E5=9B=9E=E5=A4=8D=EF=BC=9A_=5BPHP-DEV=5D_How_should_I_call_a_PHP_function?= From: derick@php.net (Derick Rethans) --8323329-1542724339-1408438521=:4107 Content-Type: TEXT/PLAIN; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE On Tue, 19 Aug 2014, Wei Dai wrote: > > On Mon, 18 Aug 2014, Wei Dai wrote: > > =20 > > > > I'm trying to call a function inside a module, a PHP_FUNCTION. > > > > Other than zend_eval_stringl, what's the direct way to do it? > > > Please refer to call_user_function and call_user_function_ex. > > > > Actually, you need to be careful with this. If you are calling=20 > > another PHP function in the same extension, do *not* use=20 > > call_user_function. Instead, create a common C function that you=20 > > can call from whereever you need to. call_user_function(_ex) is not=20 > > fast. > > =20 > i agree. =20 >=20 > here is a scenario: >=20 > i was wrote an extension, and i need to call some PHP function like=20 > =E2=80=9Cstrtr (http://lxr.php.net/s?defs=3Dstrtr&project=3DPHP_5_4)=E2= =80=9D =E2=80=9C*trim" or=20 > a function in another extension but it doesn=E2=80=99t have a common C=20 > function. However, i don=E2=80=99t want to copy the implement code into m= y=20 > extension. >=20 > so, i have two options: >=20 > 1. copy the duplicate code into my extension, It can be fast in this=20 > way, but the code is not beautiful. > > 2. call call_user_function(_ex) , it=E2=80=99s slower than the first opti= on,=20 > but the code is more simple and beautiful than the first option. or: 3. refactor the functionality in PHP so that trim or others *can* be=20 used in extensions. I would not pick option 2, especially not if you're going to call this=20 function a lot. Calling a PHP function directly involves a lot more=20 overhead than just calling a C-function.=20 cheers, Derick --=20 http://derickrethans.nl | http://xdebug.org Like Xdebug? Consider a donation: http://xdebug.org/donate.php twitter: @derickr and @xdebug Posted with an email client that doesn't mangle email: alpine --8323329-1542724339-1408438521=:4107--