public static function toString( $value, $with_type = FALSE, $max_size = self::TOSTRING_MAX_LENGTH, $tostring_methods = '__toString,toString' )
    {
        $ret = '';

        if ( $value === NULL ){
            $ret = 'NULL';
        }
        else{
            $type = gettype($value);
            switch( $type ){
            case 'string':
            case 'integer':
            case 'double':
            case 'boolean':
            case 'NULL':
            case 'unknown type':
                $ret = strval($value);
                if ( $with_type ){
                    $ret .= '(' . $type . ')';
                }
                break;
            case 'array':
                $ret = '';
                foreach( $value as $k => $v ){
                    if ( strlen($ret) > 0 )        $ret .= '/';
                    $ret .= "$k=" . self::toString( $v );
                    if ( $with_type ){
                        $ret .= '(' . gettype($v) . ')';
                    }
                }
                break;
            case 'object':
                {
                    $methods = explode( ',', $tostring_methods );
                    foreach( $methods as $method ){
                        if ( method_exists($value, $method) ){
                            $ret = $value->{$method}();
                            break;
                        }
                    }
                    if ( $with_type ){
                        $ret .= '(' . get_class($value) . ')';
                    }
                }
                break;
            }
        }

        if ( $max_size > 0 ){
            return strlen($ret) > $max_size ? substr($ret,0,$max_size) . '...' : $ret;
        }
        else{
            return $ret;
        }
    }