Array operator overloading

February 3, 2008

ArrayAccess interface is an excellent offer from PHP. Though I do not personally like the idea of operator overloading, this interface can be a great tool for developing application faster and neatly by overloading the array access.

The interface is to be implemented by a class and override the accessors methods.

Class diagram of ArrayAccess interface

I am giving a simple code that demonstrate its usage.

 class MyArray implements ArrayAccess {       
    private $arr = array();

    function offsetExists($name) {              
        return isset($name);
    }

    function offsetGet($name) {       
        return $arr[$name];
    }

    function offsetSet($key, $val) {       
        $arr[$key]=$val;
    }

    function offsetUnset($name) {       
        unset($arr[$name]);
    }
}
$arr = new MyArray();
$userMap["Hello"]="Worlds";
echo $userMap["Hello"];

This class can use a database for its model. The interface facilitates coding array style with similar __get() __set() functionalities for classes.

Btw, anybody knows how I can show codes like code in an editor with line number ?


PHP with NetBeans

February 1, 2008

I am always a fan of Java. And like NetBeans as well. Though it used to be slow, but the latest release netbeans 6 is super fast, it may be due to the latest jre. Using the the latest jre, old java swing applications are now super fast!!! Believe me, better else try yourself. I am sure swing will come well into the desktop market in near future (it till then the desktop idea survives :P )

Anyway, I was searching for an IDE for PHP with auto completion feature. Having downloaded the netbeans6 I was surprise to find a plug-in named PHP! Downloaded it and got exactly what I was looking for :)

For more information visit Php plug-in for netbeans.