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


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to