Overloading

by zaachi on July 30th, 2010
No notes
Syntax: PHP
Show lines - Hide lines - Show in textbox - Download
//set E_ALL errors
error_reporting(E_ALL);
 
/*
//my Exceptions
class _BlobalExceptions extends Exception
{
    //save exception
}
*/
 
class _Global //implements ... /* no need */
{
    public function __construct(Array $params = array())
    {
        //set variables
        if( is_array( $params ) && $params ) //if count
        {
            foreach($params as $id => $value )
            {
                $this->setVariable($id, $value);
            }
        }
    }
 
    protected function __set($id, $value)
    {
        $this->$id = $value;
    }
 
    protected function __get($name)
    {
 
    }
 
    protected function __isset($name)
    {
        return isset($this->$name);
    }
 
    protected function __call($fn, $param)
    {
        //set var's from params
        $var = array_key_exists(0, $param) ? $param[0] : false;
        $val = array_key_exists(1, $param) ? $param[1] : false;
 
        //calling setter
        if( substr($fn, 0, 3) == 'set')
        {
            if( $var && $val )
            {
                $this->$var = $val;
                return true;
            }
            return false;
        }
        //calling getter
        else if( substr($fn, 0, 3) == 'get')
        {
            if( isset( $var ) )
            {
                return $this->$var;
            }
            return false;
        }
    }
}

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS