Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:97938 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 80300 invoked from network); 23 Jan 2017 17:25:31 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Jan 2017 17:25:31 -0000 Authentication-Results: pb1.pair.com header.from=adambaratz@php.net; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=adam.baratz@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.43 as permitted sender) X-PHP-List-Original-Sender: adam.baratz@gmail.com X-Host-Fingerprint: 209.85.214.43 mail-it0-f43.google.com Received: from [209.85.214.43] ([209.85.214.43:37006] helo=mail-it0-f43.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 4D/13-00729-A8C36885 for ; Mon, 23 Jan 2017 12:25:30 -0500 Received: by mail-it0-f43.google.com with SMTP id r185so71652148ita.0 for ; Mon, 23 Jan 2017 09:25:30 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=l1W///24c+wHVLaVLkVQvlIkFpD3QE0Y0S+qblT0GTo=; b=Mu71ympmZL0jQhpJXw1VJarurDDnJ58hNjA2Mtx0D0O+rgs7Q/rWJSBfpuPc0h+lhh lfn7i+eGFECBOUfjfC71d2j7mKGn3pN6JggPvwG8HOhOBTcTmua7v2JJl6ENIIixht4Z pp+NsD+XzsCSS4i48w5kzln8EENFJtNkSc2lwCTYm1AVkx2VFlsMCrUc9qR0nA477IPn yNPUZfvYWEDq85KuSOqrLsi33F4UtNIjtvy5/Hxw80sNi02R7gjmJ1r0sgmaDuF75wOs ucFMwREgeIVbMWcT8vlfk5E7ZNfeVkbcbq1lygl1XKJTQKo+L99loQiPPELQI1DIqXsq MZew== X-Gm-Message-State: AIkVDXJuXzGvyr3yUimlK0niFzgxVH/RjDETG406EzoInudAnGxUr/UpaX+P1zGnaxqkkA== X-Received: by 10.36.116.71 with SMTP id o68mr17062271itc.60.1485192327996; Mon, 23 Jan 2017 09:25:27 -0800 (PST) Received: from mail-it0-f48.google.com (mail-it0-f48.google.com. [209.85.214.48]) by smtp.gmail.com with ESMTPSA id a4sm6849747ioa.43.2017.01.23.09.25.27 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Jan 2017 09:25:27 -0800 (PST) Received: by mail-it0-f48.google.com with SMTP id c7so71094910itd.1 for ; Mon, 23 Jan 2017 09:25:27 -0800 (PST) X-Received: by 10.36.19.133 with SMTP id 127mr15194689itz.3.1485192327703; Mon, 23 Jan 2017 09:25:27 -0800 (PST) MIME-Version: 1.0 Received: by 10.64.146.10 with HTTP; Mon, 23 Jan 2017 09:25:27 -0800 (PST) In-Reply-To: <1484727448.3119.8.camel@toro.home> References: <1484727448.3119.8.camel@toro.home> Date: Mon, 23 Jan 2017 12:25:27 -0500 X-Gmail-Original-Message-ID: Message-ID: To: Torsten Rosenberger Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=001a114633621dcb4f0546c64980 Subject: Re: [PHP-DEV] writing extensions best practice, pass an object as parameter From: adambaratz@php.net (Adam Baratz) --001a114633621dcb4f0546c64980 Content-Type: text/plain; charset=UTF-8 > > but how can i pass the object from a private method of the PHP extension > class to the setcallbackfunction as it is down in PHP with > > array(&$this, '_htmlentities') > I usually find reading the source for standard library functions to be helpful for learning how to do things. array_map could help with capturing a callable and then doing something with it: https://github.com/php/php-src/blob/master/ext/standard/array.c#L6005 so the PHP Class with opcache ist equal faste as my extension. > My goal was to write the class as an extension to get faster. > Is the constructor where the bulk of the computation happens? Given that this is a templating tool, it's probably during render. My guess of what you'd get out of rewriting in C is greater control over string manipulation and related memory allocation. That said, if you're hitting performance issues, I might suggest looking into another templating tool that's more actively maintained. Extensions are generally harder to maintain than userland code. If you succeed in writing a faster version of this tool, this could turn into a "now you have two problems" situation[1]. If at all possible, it'd be better to let an existing community solve performance issues for you. The last question should I use call_user_function or write this function > in C. > Call the internal function directly for less overhead. Hope this helps! Adam --- [1] http://regex.info/blog/2006-09-15/247 --001a114633621dcb4f0546c64980--