While it may certainly seem "lazy" I spend a large portion of my time in javascript and I like the syntax for arrays.

I cant seem to figure out if I can "prototype" the array "object" and give it methods that simply returns the appropriate function:


$aMyArr = array();


array->push = function ($Foo) { if isset($Foo) { this[] = $Foo; }; }; // I am quite aware this is not valid. Demo purposes

if this is possible, is this going to make a large overhead just for ease of use?

The only other thing I can think of doing is making a new class that has one protected var that is an array, and cloning all the methods... which is basically what Im doing, but I don't want to call it class "myArr"... and then I have to make a constructor that will iterate what is passed in... and stuff... :-/

3 Years
Discussion Span
Last Post by pritaeas

Since array is not a class, I think what you describe in your last paragraph is the way to go.

Whether it's overhead... I wouldn't implement it but if you find this easier/better to use, then why not.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.