Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:38770 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 81611 invoked from network); 4 Jul 2008 16:04:15 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Jul 2008 16:04:15 -0000 Authentication-Results: pb1.pair.com smtp.mail=info@adaniels.nl; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=info@adaniels.nl; sender-id=unknown Received-SPF: error (pb1.pair.com: domain adaniels.nl from 82.94.236.173 cause and error) X-PHP-List-Original-Sender: info@adaniels.nl X-Host-Fingerprint: 82.94.236.173 loco.helderhosting.nl Linux 2.5 (sometimes 2.4) (4) Received: from [82.94.236.173] ([82.94.236.173:35048] helo=loco.helderhosting.nl) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E4/5E-14155-EF94E684 for ; Fri, 04 Jul 2008 12:04:14 -0400 Received: from [10.2.1.121] (a82-95-179-89.adsl.xs4all.nl [82.95.179.89]) by loco (Postfix) with ESMTP id CDA11C18048; Fri, 4 Jul 2008 18:04:11 +0200 (CEST) Message-ID: <486E49FC.40107@adaniels.nl> Date: Fri, 04 Jul 2008 18:04:12 +0200 User-Agent: Thunderbird 2.0.0.14 (X11/20080505) MIME-Version: 1.0 To: 'PHP Internals' Cc: stefan.priebsch@e-novative.de Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Zend core: Calling methods on array From: info@adaniels.nl (Arnold Daniels) Hi all, Recently on the Dutch PHP convention I talked with Stefan Priebsch about a new feature that I think would be a great addition to PHP. There are a lot of array functions like count($array) and array_push($array, $value). This has worked well for the past decade or so. However I would find it more clear to do $array->count() and $array->push($value). My first idea was to simply replace arrays for objects with array access, but Stefan correctly pointed out that this would probably break code and would not be beneficial for performance. So I set out to find a less intrusive way of implementing it. All functions are registered to a function table. This patch adds a new table to register functions as array methods. If a method is called on an array, the function is looked up from this table and the array is (or should be) pushed on the stack as first argument. This way should not break any code and to my knowledge doesn't influence performance of existing code (at runtime). Unfortunately I'm not an experienced PHP internals developer, let alone a Zend core hacker. Most of the code was quite understandable, so I managed to get is mostly working. The methods are registered in the array method table, the function is grabbed and called, but the array isn't placed on the stack. The patch can be downloaded at http://demo.adaniels.nl/php5-array_methods.diff.zip I could really appreciate if any of you core developers could have a look at the patch to see where the problem lies. Discussions are welcome, but please have an open mind. - Arnold